RequestBody校验空
时间: 2023-10-14 19:31:47 浏览: 64
SpringBoot服务端数据校验过程详解
在校验@RequestBody参数时,@Validated注解不会生效。您可以使用@Validated和@Valid注解配合使用来校验List类型的参数。在具体的实体类型中添加校验注解,比如@NotEmpty(message = "等级id不能为空")。另外,在异常处理中,可以使用@ExceptionHandler(ConstraintViolationException.class)来处理@Valid注解引发的异常。在处理异常的方法中,可以通过ex.getConstraintViolations()获取到校验失败的信息,并进行相应的处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [@Validated + @RequestBody校验List](https://blog.csdn.net/qq_35563821/article/details/118105274)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [开源版发卡小程序源码 云盘发卡微信小程序源码带PC端 云盘发卡系统源码.rar](https://download.csdn.net/download/winkexin/88236712)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文