lombok@NonNull 注解无法对 SpringMVC 封装请求的对象的 Field 进行非空校验

Java58

```java;gutter:true;
If put on a parameter, lombok will insert a null-check at the start of the method / constructor's body, throwing a {@code NullPointerException} with the parameter's name as message. If put on a field, any generated method assigning a value to this field will also produce these null-checks.

```

可见 @NonNull 注解用于标注Field时,并非是直接校验所标注字段不能为空,而是对赋值该字段的方法加 null 校验。

如该对象

```java;gutter:true;
@Data
@AllArgsConstructor
public class ReqIn {

@NonNull
private Byte name;

private String id;

public ReqIn(){
输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长