方式一:后台直接接收,列出所有参数,设置默认值为空,这样mybatis判断时不会出现找不到参数属性的情况
@RequestBody为接收json或者实体对象必备
/**
* 方法描述: 获取数据
*/
@RequestMapping("getData")
public Object getData(
@RequestParam(value = "startTime", defaultValue = "") String startTime,
@RequestParam(value = "endTime", defaultValue = "") String endTime,
@RequestParam(value = "subjectId", defaultValue = "") String subjectId,
@RequestParam(value = "doctorId", defaultValue = "") String doctorId
){
Map<String, Object> map = new HashMap<String, Object>();
List<ReturnRateDto> list = new ArrayList<ReturnRateDto>();
map.put("startTime", startTime);
map.put("endTime", endTime);
map.put("subjectId", subjectId);
map.put("doctorId", doctorId);
try {
if(doctorId!=null&&!doctorId.equals("")&&!doctorId.equals("null")){
list = returnRateService.getOneData(map);
}else{
list = returnRateService.getData(map);
}
} catch (Exception e) {
e.printStackTrace();
return new Response(ExceptionMsg.FAILED);
}
return list;
}
方式二 : 用map形式接收,需前端传递参数并附上初始值,否则后台无法断定传递了哪些参数,未传递哪些参数
/**
* 方法描述: 数据显示
*/
@RequestMapping("getData")
public Object getData(
@RequestBody Map<String,Object> data
){
List<ReportBaseDto> list = new ArrayList<ReportBaseDto>();
try {
list = acceptsNumService.getShowData(data);
} catch (Exception e) {
e.printStackTrace();
return new Response(ExceptionMsg.FAILED);
}
return list;
}
方式三:用实体对象接收 效果同上
/**
* 方法描述: 数据显示
*/
@RequestMapping("getData")
public Object getData(
@RequestBody User user
){
List<ReportBaseDto> list = new ArrayList<ReportBaseDto>();
try {
list = acceptsNumService.getShowData(data);
} catch (Exception e) {
e.printStackTrace();
return new Response(ExceptionMsg.FAILED);
}
return list;
}