springboot list 参数怎么使用@NotNull
时间: 2024-04-25 16:24:55 浏览: 167
springboot中用fastjson处理返回值为null的属性值
回答: 在Spring Boot中,如果你想要对一个List类型的参数进行非空校验,你可以使用@NotNull注解。\[2\]在你的Controller层的方法参数上添加@Valid注解,这样就可以触发参数校验。同时,在pom.xml文件中添加spring-boot-starter-validation依赖,以确保校验功能可用。\[1\]这样,当你的接口被调用时,如果传入的List参数为空,就会触发校验错误。这样可以确保参数的准确性和完整性。
#### 引用[.reference_title]
- *1* [18.日常问题整理[2022/7/26]【SpringBoot】校验-@valid、@NotBlank、@NotEmpty、@NotNull注解使用场景及...](https://blog.csdn.net/weixin_46876034/article/details/125979214)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [SpringBoot注解@NotBlank@NotNull@NotEmpty不生效的原因](https://blog.csdn.net/Lazy_Goat/article/details/118890847)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [springboot注解@NotNull,@NotBlank,@Valid自动判定空值](https://blog.csdn.net/lisheng19870305/article/details/114442126)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文