今天学到的两点
第一个:
示例:
@GetMapping("/getRecordList")
public Object getRecordList(@Param("DisabledListReq") DisabledListReq disabledListReq,
HttpServletRequest request) throws ParseException {}
// 类
public class DisabledListReq {
private static final long serialVersionUID = 1L;
// 服务时间 YYYY-MM
private String paramMonth;
}
springboot框架中 ,我一开始是用 Date 类型
private Date paramMonth;
然后在接收参数时,报类型转换错误,但是呢,我还想用Date,然后我就用了@Jsonformat ,结果肯定还是错误。因为Jsonformat 对返回参数做日期格式化。
最后,我还是用了 String。
第二个:
还是上面的代码
@GetMapping("/getRecordList")
public Object getRecordList(@RequestParam ("DisabledListReq") DisabledListReq disabledListReq,
HttpServletRequest request) throws ParseException {}
@RequestParam 这里,我一开始用的时@RequestParam ,然后传参(json对象)的过程中就一直报错,
org.springframework.web.bind.MissingServletRequestParameterException: Required DisabledListReq parameter 'disabledListReq' is not present
提示没有获取到相应的参数,接下我就来来回回看前后端,尝试修改,浪费了好长时间
最后把RequestParam 去掉就可以获取到参数了
原来:RequestParam 是为了解决前台参数名称与后台接收参数变量名称不一致的问题
然后就没有DisabledListReq 这个参数,能不报错吗