控制层参数注解使用

@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));
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值