给前端传值的技巧:
在前后端分离的项目中,前端要的数据,可能是几张表的数据,这时候如果都放到list中,前端不好获取。
我们可以用一个对象来接收,把这几个表的字段都封装到一个对象里面,然后传过去。就是适当的在对象里面添加属性。
接收前端的json数组:
一个对象中的属性 List<Map>pic
对象:
{"name": "ww", "desc": "ww", "remark": "ww", "kind": "3221032bd425497f9cd541679c63b504", "type": "4","delay": "0","shiftType":"0","pointName":"","pointId":"","alarmRemindList":[]}
数组:
["63b070e72f0a4fb2a00bb58d94dbb730","dsfosdsdosdfsodfsdfsosdfsd"]
传的格式如下:
处理
@RequestBody Map<String,Map> map
@RequestMapping("getListByAll") @ResponseBody public DataResult getListByAll(@RequestBody Map<String,Map> map, HttpServletRequest request) { PageInfo<WpSbxx> listByMes = null; try { listByMes = wpSbxxService.getListByAll(Integer.parseInt(map.get("pageNum").get("pageNum").toString()), Integer.parseInt(map.get("pageSize").get("pageSize").toString()), map.get("maps"),map.get("All").get("All").toString(),request); } catch (Exception e) { e.printStackTrace(); return DataResult.getResult(BaseResponseCode.OPERATION_ERROR.getCode(), "查询失败"); } return DataResult.success(listByMes); }
Json格式传参格式:
{ "pageNum":{"pageNum":1}, "pageSize":{"pageSize":20}, "maps":{}, "All":{"All":""} }
后端处理这种结构的json数据:
一:
二:
三:
{ "pic": [ {"url":"/3213223133.png","name":"图片.png"}, {"url":"/3213223133.png","name":"图片.png"} ] }
{ "name": "李雷", "password": "韩梅梅", "major ": [{ "favorite": "英语 " }, { "second": "语文 " }] }