lombok常用注解
- @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@AllArgsConstructor
@Builder
public class GamesInfo {
@NotBlank(message = "userId can not be blank")
private String userId;
@NotBlank(message = "mobile can not be blank")
private String mobile;
@NotBlank(message = "activityId can not be blank")
private String activityId;
private int players;
@NotBlank(message = "stub can not be blank")
private String stub;
private boolean activityStatus;
@JsonIgnore
@NotBlank(message = "stub can not be blank")
private String score;
@JsonIgnore
@NotBlank(message = "maxScore can not be blank")
private String maxScore;
}
1. @Getter 注解和@Setter 放在类上 ,省去当前类为每个属性写get方法和set方法
2. @NoArgsConstructor 省去写类的无参构造方法
3. @AllArgsConstructor 类的全参构造方法
4. @Builder 提供创建类对象的builder方法,可以通过 GamesInfo.builder().userId("2").build();方式创建
5. @JsonIgnore 注解放在属性方法上,该字段在返回给前端时,json串中不会出现该字段
6. @NotBlank(message = "maxScore can not be blank") 放在类属性上,在请求校验对象属性时使用,与注解@RequestBody @Validated GamesInfo gamesInfo 配好使用
7. @Data 注解也是提供get、set方法
8. @Slf4j 提供日志类方法