@RequestParam
参考文档网址:https://blog.csdn.net/hellostory/article/details/7519358
@RequestMapping(value = "/index")
public String index(@RequestParam(value = "action", required = false)
String action, @RequestParam(value = "notIncludeTypeId", required = false)
int notIncludeTypeId){
// .... 省略代码
}
1、当required 的值为false 时 使用这个注解可以不传这个参数,为 true时必须传;required默认值是true。
1.2、requied=false ,不传值报错,使用参数类型的默认值。requied=true,不传值报错,即抛出异常。
2、当可选参数“notIncludeTypeId”不存在时,Spring默认将其赋值为null,但由于notIncludeTypeId已定于为基本类型int,所以赋值失败。
解决方法:
建议使用包装类型代替基本类型,如使用“Integer”代替“int”。
@NotEmpty
参考文档网址:https://blog.csdn.net/king_qc/article/details/81390396
@NotEmpty支持的是字符串类型字段
在Integer类型的字段上使用@NotEmpty,会报错。
用@NotNull就不会
public Result<ReportVoucherLogPageVO> queryVoucherReportList(@NotBlank(message = "报文业务日期不能为空 yyyy-MM格式")
@RequestParam(value = "businessDate", required = false)
@ApiParam(value = "报文业务日期 yyyy-MM")
@Pattern(regexp = "\\d{4}-(0[1-9]|1[0-2])", message = "时间格式不正确 yyyy-MM")
String businessDate,
@NotNull(message = "当前页不能为空")
@RequestParam(value = "current", required = false)
@ApiParam(value = "当前页")
Integer current,
@NotNull(message = "查询数据条数不能为空")
@RequestParam(value = "pageSize", required = false)
@ApiParam(value = "查询数据条数")
Integer pageSize) {
return MSTemplateAdapter.op(() -> financeReportService.queryVoucherReportList(businessDate, current, pageSize));
}