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

  • 相关阅读:
    mysql修改库、表、字段 字符集,中文排序
    CENTOS6.5 编译安装MySQL5.7.14
    自己的一个小小的目标
    css 浮动和清除浮动
    移动端调试方法
    Fiddler抓包工具总结
    Vue中错误图片的处理
    跨域资源共享 CORS 详解
    十大排序算法JavaScript实现总结
    javascript实现二叉搜索树
  • 原文地址:https://www.cnblogs.com/zhz-8919/p/11187746.html
Copyright © 2020-2023  润新知