标签:
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/jquery-1.7.2.min.js"></script>
//前端界面调用资源文件要加上request.getContextPath()上下文件路径,此resources资源(jq.js..)是放在META-INF WEB-INF同一目录下
//方问这个文件也会出现一个问题就是跟web.xml里面为spring servlet定义的url-parten冲突,先将这个改为 <url-pattern>/hello/*</url-pattern>就可以了,但是我又不想以hello开头呢?那就用激活Tomcat的defaultServlet来处理静态文件。
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>不做静态资源请求的映射。
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
</head>
<body>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
var saveDataAry=[];
var data1={"userName":"test","address":"gz"};
var data2={"userName":"ququ","address":"gr"};
saveDataAry.push(data1);
saveDataAry.push(data2);
$.ajax({
type:"POST",
url:"user/saveUser",
dataType:"json",
contentType:"application/json",
data:JSON.stringify(saveDataAry),
success:function(data){
}
});
});
</script>
后台JAVA代码只要用List<User>就可以了
@RequestMapping(value = "/user/saveUser", method = {RequestMethod.POST })
@ResponseBody
public void saveUser(@RequestBody List<User> users) {
for(User u:users)
{
}
}
标签:
原文地址:http://www.cnblogs.com/rrtt/p/5847102.html