SpringMVC 参数中接收之一 List

作者:张艳涛

time:2020-07-31


SpingMVC

、前台传数组,SpingMVC用addusers(@RequestBody List<UserPojo> userlist){ 接收

前台vue发送的数据

           let data = [this.form]
            this.apiPost('acountmanage/addusers', data).then((res) => {
              this.handelResponse(res, (data) => {
                _g.toastMsg('success', '添加成功')
                _g.clearVuex('setUsers')
                setTimeout(() => {
                  this.goback()
                }, 1500)
              }, () => {
                this.isLoading = !this.isLoading
              })
            })

post中发送的格式

即为:[{key:value,K2:V2,....}]

后台接收处理

    @ResponseBody
    @CrossOrigin
    @RequestMapping(value ="/addusers",produces = {"application/json;charset=UTF-8"})
    public String addusers(@RequestBody List<UserPojo> userlist){

        try {
            //List<UserPojo> userlist = (ArrayList<UserPojo>)params.get("usersinfo");

            TradeInfo tradeInfo = new TradeInfo();
            String tradeType ="ADDUSERS";
            tradeInfo.addData("tradeType",tradeType);
            tradeInfo.addData("addusers",userlist);

  

说明:这里能看到 spring 已经识别到了List数据,并且将{} 转换成了一个UserPojo对象

原文地址:https://www.cnblogs.com/zytcomeon/p/13409975.html