看了网上不少人的解决办法,都不怎么方便,今天试了下,还真有一步到位的方法
js部分的代码:
var array = [];
for (var i = 0; i < nodes.length; i++) {
array.push(nodes[i].id);
}
$.ajax({
type: type,
url: url,
data: {nodeList: array.toLocaleString()},// array.toLocaleString()的结果是 1,2,3 这种
dataType: "json",
success: function (result) {
}
error: function () {
}
});
后台controller的部分,两种方式,一种是对象中有list,一种是直接list,都可以取到
//方式1
public ResultInfo saveRoleMenu(@RequestParam(value = "nodeList") List menuList) {
}
//方式2
public ResultInfo saveRoleMenu(User user) {
}
class User{
private List nodeList;
//get set
}
提供给大家参考