1.pojo對象:
使用ajax的post方法傳遞,后台可以直接按pojo類型接收:
$scope.save=function() { $.post('../brand/save', $scope.brand, function (response) { if(response.status) { $scope.reloadList(); } else { alert(response.message); } }, "json"); }
2.數組類型:
使用angualajs的get方法傳遞,后台可以直接按數組類型接收:
```
// 刪除多個
$scope.delMany=function () {
$scope.listIds = [];
// 定義被選中id數組
$("input[type='checkbox']:gt(0):checked").each(function() {
// $("#" + $(this).val()).remove();
$scope.listIds.push(this.value);
//alert($(this).val());
});
if (confirm("確定要刪除嗎?")) {
$http.get('../brand/delMany?listIds=' + $scope.listIds).success(function (response) {
if(response.status) {
$scope.reloadList();
} else {
alert(response.message);
}
});
}
}
```
3.同時傳遞傳遞pojo+基本數據類型
使用angularjs的post方法傳遞
步驟1:聲明pojo對象
//定義搜索對象
$scope.searchEntity={};
步驟2:基本數據類型使用參數拼接,pojo類型單獨傳參
//分頁
$scope.findPage=function(page,rows){
$http.post("../brand/findPage?page="+page+"&rows="+rows,$scope.searchEntity).success(function (response) {
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total
});
步驟3:在后台controller中,把接收pojo對象的參數使用@RequestBody修飾
@RequestMapping("/findPage")
public PageResult<Brand> findPage(@RequestBody Brand searchEntity,Integer page,Integer rows) {
return brandService.findPage(searchEntity,page, rows);
}
注意:angualajs的$http.post方法只能傳遞json類型