springBoot + vue用axios的post方法传对象数组

前台vue代码

export default {
  name: 'Logistics',
  data () {
    return {
      processes: [
        {
          id: '1',
          message: '新员工入职教育培训',
          status: '2'
        },
        {
          id: '2',
          message: '参画申请',
          status: '2'
        }
      ]
    }
  },
  methods: {
    update (index) {
      let params = {
        params: this.processes
      }
      this.axios
        .post('/api/updateNode', params)
        .then(response => {
          console.log(response.data)
        })
        .catch(response => {
          console.log(response)
        })
    }
  }
}

后台用RequestBody接受json数据

@PostMapping("/updateNode")
	public ResponseEntity<JsonResult> updateNode(@RequestBody String params){
		JSONObject j1 = JSONObject.parseObject(params);
		List<Node> nodes = JSONObject.parseArray(j1.getJSONArray("params").toJSONString(), Node.class);
		JsonResult r = new JsonResult();
		try {
			processService.updateNode(nodes);
			r.setMsg("ok");
		} catch (Exception e) {
			r.setObj(e.getClass().getName() + ":" + e.getMessage());
			r.setMsg("error");
			e.printStackTrace();
		}
		return ResponseEntity.ok(r);
	}

版权声明:本文为zwy15841139493原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。