COMPLEX-B

导航

js往后台传参的方式

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类型

posted on 2019-07-15 11:16  COMPLEX-B  阅读(3940)  评论(0编辑  收藏  举报