网上各种说json数据的各种好处,但是之前前后端自己一个人做,体会不到json的好,
突然有前端写页面,告诉我所有交互数据都是json,很爽啊有木有.
大多数情况下正好接受要么数据少的时候,把参数放到请求后,要么数据多正好有实体对应,
就那么少数情况下,参数也不多,但总拼接多链接后感觉很low,就想到,json可是使用对象接受,
但json本质就是一个map形式的数据格式,直接使用map应该可以吧,网上查了查,想法没毛病
/**
* @Description: 查询需要到货的运单/车辆
* @return
* @exception
*/
@RequestMapping("/arrive/search")
@ResponseBody
public JsonResult searchConvey(@RequestBody GoodArriveModel arriveModel ){
String type = arriveModel.getType();
String company = ContextHepler.getCompanyName();
try{
if("单票".equals(type)){
return orderService.searchGoodArriveByYdbhid(arriveModel.getYdbhid(),company);
}
//整车
Date fchrq = DateRangeUtil.getDate(arriveModel.getFchrq());
return orderService.searchGoodArriveByChxh(fchrq,arriveModel.getChxh(),company);
}catch(Exception e){
JsonResult jsonResult = new JsonResult();
jsonResult.put("resultCode", 400);
jsonResult.put("reason", "查询条件有误");
return jsonResult;
}
}
/**
*
* @Description: 到货的保存
* @param map 接受前台传递的json数据
* @return
* @exception
*/
@RequestMapping("/arrive/save")
@ResponseBody
public JsonResult saveGoodArrive(@RequestBody Map<String,Object> map){
String grid = ContextHepler.getCurrentUser().getAccount();
try{
return orderService.saveGoodArrive(map,grid);
}catch(ParameterException pe){
JsonResult jsonResult = new JsonResult();
jsonResult.put("resultCode", 400);
jsonResult.put("reason", "参数有误,请勿乱操作");
return jsonResult;
}catch (Exception e) {
JsonResult jsonResult = new JsonResult();
jsonResult.put("resultCode", 400);
jsonResult.put("reason", "到货异常,请重新操作");
return jsonResult;
}
}