@RequestMapping("/postList")
@ResponseBody
public String postList(@RequestBody List<TestL> testL){
System.out.println(testL);
return null;
}
var testList=[];
var user={};
user.id=1;
user.name='jack';
testList.push(user);
var user2={};
user2.id=2;
user2.name='tom';
testList.push(user2);
$.ajax({
// headers必须添加,否则会报415错误
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
type: 'POST',
dataType: "json", //表示返回值类型,不必须
data: JSON.stringify(testList),
url: '/test/postList',
success: function(){
alert('success');
}
});
需要注意点:1、参数是数组类型
2、传入data时,转换 JSON.stringify(testList)
3、必须有headers: { 'Accept': 'application/json',
'Content-Type': 'application/json'
}
<select id="selectList" parameterType="java.util.List" resultType="java.lang.Integer">
SELECT COUNT(1) FROM t_user
WHERE id IN
<foreach collection="array" index="index" item="item"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
批量插入
<foreach collection="list" item="item" index="index" >
(UUID(),#{sdcId},now(),#{item.updateBy},now(),0)
<if test="index!=(list.size()-1)">
,
</if>
</foreach>