Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use nested objects @ NotBlank @ NotEmpty @ NotBlank

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use nested objects @ NotBlank @ NotEmpty @ NotBlank". The explanation in this article is simple, clear and easy to learn and understand. Please follow the editor's ideas to study and learn "how to use nested objects @ NotBlank @ NotEmpty @ NotBlank".

@ NotEmpty: cannot be null, and length must be greater than 0

@ NotBlank: used only on String, indicating that the value passed in cannot be null, and the length must be greater than 0 after calling trim ()

@ NotNull: cannot be null, but can be empty

If there are nested objects, just add @ Valid to the defined object

@ Valid

The way to use it is as follows, add @ Valid where the parameter is received

You can also add a global exception handling, which can also avoid writing a bunch of if to determine whether the data is empty. Of course, this also has some limitations. If you want to verify the validity of other data, you need to handle it separately, or custom annotations can be done.

@ ControllerAdvice@RestControllerpublic class GlobalExceptionHandler {@ ExceptionHandler (MethodArgumentNotValidException.class) @ ResponseBody public ResultMsgModel handleValidException (MethodArgumentNotValidException e) {Log.logger.error ("Parameter check failure" + e.getParameter () .getMethod () + "+ e.getBindingResult () .getAllErrors () .get (0) .getDefaultMessage ()); return new ResultMsgModel (ResponseCode.RETURN_VERIFICATION_FAIL,e.getBindingResult () .getAllErrors () .get (0) .getDefaultMessage () }} Thank you for your reading. The above is the content of "how to use nested objects @ NotBlank @ NotEmpty @ NotBlank". After the study of this article, I believe you have a deeper understanding of how to use nested objects @ NotBlank @ NotEmpty @ NotBlank. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report