lombok comment @Builder

  When the notes were compiled in java lombok building code, java objects to create work it can be more elegant, you do not need to write extra code repetition, which for JAVA developers is very important, after lombok appears, creating an object Builder also provides a method of work, which provides in the design of data entities, foreign keeping private setter, and to assign attributes using Builder way, this way the most elegant, but also more in line with the principles of the package, not open to the public property write!

  @Builder statement entity, that can be initialized Builder way, @ Value annotation indicates that only public getter, setter for all the properties are closed, ie private modification, so it can not only use now and @Builder

  In general, we can design entity!

  @Builder(toBuilder = true)

  @Getterpublic class UserInfo { private String name; private String email;

  @MinMoney (message = amount of not less than 0.1)

  @MaxMoney (value = 10, message = amount can not be greater than 10.) private Money price;

  }

  @Builder notes assigned a new object

  UserInfo userInfo = UserInfo.builder()

  .name(zzl)

  .email([email protected])

  .build();

  @Builder annotation modify the original object's property values

  Modifying entities, require the addition @Builder (toBuilder = true) on the entities

  userInfo = userInfo.toBuilder()

  .name(OK)

  .email ([email protected])

  .build();

  Thank you for reading!

Guess you like

Origin blog.csdn.net/qianfeng_dashuju/article/details/93496285