dependencyManagement
和之间有什么区别dependencies
?我在Apache Maven网站上看过这些文档.似乎dependencyManagement
可以在其子模块中使用在其下定义的依赖项而不指定版本.
例如:
父项目(Pro-par)在以下内容下定义依赖项dependencyManagement
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
然后在Pro-par的孩子,我可以使用junit:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有必要在父pom中定义junit?为什么不直接在所需的模块中定义它?
我在服务器端有一个Struts2动作用于文件下载.
<action name="download" class="com.xxx.DownAction">
<result name="success" type="stream">
<param name="contentType">text/plain</param>
<param name="inputName">imageStream</param>
<param name="contentDisposition">attachment;filename={fileName}</param>
<param name="bufferSize">1024</param>
</result>
</action>
Run Code Online (Sandbox Code Playgroud)
但是当我使用jQuery调用动作时:
$.post(
"/download.action",{
para1:value1,
para2:value2
....
},function(data){
console.info(data);
}
);
Run Code Online (Sandbox Code Playgroud)
在Firebug中我看到使用二进制流检索数据.我想知道如何打开用户可以在本地保存文件的文件下载窗口?
我有一个日期字符串,我想解析它到正常日期使用java Date API,以下是我的代码:
public static void main(String[] args) {
String date="2010-10-02T12:23:23Z";
String pattern="yyyy-MM-ddThh:mm:ssZ";
SimpleDateFormat sdf=new SimpleDateFormat(pattern);
try {
Date d=sdf.parse(date);
System.out.println(d.getYear());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我有一个例外: java.lang.IllegalArgumentException: Illegal pattern character 'T'
所以我想知道我是否必须拆分字符串并手动解析它?
顺便说一句,我试图在T的两边添加单引号字符:
String pattern="yyyy-MM-dd'T'hh:mm:ssZ";
Run Code Online (Sandbox Code Playgroud)
它也行不通.
单向和双向关联有什么区别?
由于在db中生成的表都是相同的,因此我发现的唯一区别是双向关联的每一侧都将引用另一侧,而单向不引用.
这是一个单向关联
public class User {
private int id;
private String name;
@ManyToOne
@JoinColumn(
name = "groupId")
private Group group;
}
public class Group {
private int id;
private String name;
}
Run Code Online (Sandbox Code Playgroud)
双向关联
public class User {
private int id;
private String name;
@ManyToOne
@JoinColumn(
name = "groupId")
private Group group;
}
public class Group {
private int id;
private String name;
@OneToMany(mappedBy="group")
private List<User> users;
}
Run Code Online (Sandbox Code Playgroud)
区别在于该组是否拥有用户的参考.
所以我想知道这是唯一的区别吗?哪个推荐?
我发现如果a
页面中没有链接到新页面的链接,那么当用户点击它时,元素周围会有一条虚线,只有当用户点击页面中的其他内容时,它才会消失,如何删除这个?
例:
注意元素周围的虚线Section 2
.
我的页面中有一些无线电,当被检查的无线电改变时我想做一些事情,但是代码在IE中不起作用:
$('input:radio').change(...);
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后,人们建议使用点击.但它不起作用.
这是示例代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$('document').ready(
function(){
$('input:radio').click(
function(){
alert('changed');
}
);
}
);
</script>
</head>
<body>
<input type="radio" name="testGroup" id="test1" />test1<br/>
<input type="radio" name="testGroup" id="test2" />test2<br/>
<input type="radio" name="testGroup" id="test3" />test3</br>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它在IE中也不起作用.
所以我想知道发生了什么?
如果我点击一个已检查的收音机,我担心是否会重新触发更改事件?
更新:
我无法添加评论,所以我在这里回复.
我使用IE8和链接Furqan给我也不能在IE8中工作.我不知道为什么...
在我的应用程序中,我需要在某些地方获取一些位图drawable,我不想保留引用R
.所以我创建了一个类DrawableManager
来管理drawables.
public class DrawableManager {
private static Context context = null;
public static void init(Context c) {
context = c;
}
public static Drawable getDrawable(String name) {
return R.drawable.?
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想通过这个名字得到drawable(car.png放在res/drawables中):
Drawable d= DrawableManager.getDrawable("car.png");
Run Code Online (Sandbox Code Playgroud)
但是正如您所看到的,我无法通过名称访问资源:
public static Drawable getDrawable(String name) {
return R.drawable.?
}
Run Code Online (Sandbox Code Playgroud)
任何替代品?
我是hibernate的新手,在阅读了hibernate api和教程后,看来会话应该在不使用时关闭.
像这样:
Session sess=getSession();
Transcration tx=sess.beginTranscration();
//do something using teh session
sess.save(obj);
tx.commit();
sess.close;
Run Code Online (Sandbox Code Playgroud)
在独立应用程序中使用它时我毫无疑问.但是我不确定何时在网络应用中使用.
例如,我有一个servlet:TestServlet
从客户端接收参数,然后我调用Manager来根据参数查询,就像这样:
class TestServlet{
doGet(HttpServletRequset,httpServletResponse){
String para1=request.getParam...();
String para2=.....
new Manager().query(para1,para2);
}
}
class Manager{
public String query(String pa1,String pa2){
Session=....// get the session
//do query using para1 and 1
session.close() //Here, I wonder if I should close it.
}
}
Run Code Online (Sandbox Code Playgroud)
我应该在查询方法中关闭会话吗?
因为有人告诉我,hibernate中的会话就像jdbc中的连接一样.那么频繁打开和关闭它是正确的方法吗?
顺便说一句,每次都需要tx.commit()吗?
还有什么是在servlet中使用session的线程问题,因为我看到会话在api中不是线程安全的.
@Test
public void testListCur(){
List<String> li=new ArrayList<String>();
for(int i=0;i<10;i++){
li.add("str"+i);
}
for(String st:li){
if(st.equalsIgnoreCase("str3"))
li.remove("str3");
}
System.out.println(li);
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我将抛出一个ConcurrentModificationException.
看起来当我从列表中删除指定的元素时,列表不知道它的大小是否已被更改.
我想知道这是集合和删除元素的常见问题吗?
我有一个名为的javascript文件main.js
.
在里面main.js
我想得到这个当前文件的绝对路径,如:
http://server/app/main.js
http://server/app/script/main.js
Run Code Online (Sandbox Code Playgroud)
获得绝对路径的最快方法是什么?