说明
Accessors注解的属性设置
chain = true 链式访问
fluent = true 区别在于getter和setter不带set和get前缀
prefix = "f" set方法忽略指定的前缀,推荐这样去命名。
fluent示例
import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.experimental.Accessors; @Accessors(fluent = true) @Data @ToString @EqualsAndHashCode public class ResultBean{ private String code; private String message; private T data; public void test1(){ ResultBean r = new ResultBean<>(); r.code("200").data("111"); } }
chain 示例
import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.experimental.Accessors; @Accessors(chain = true) @Data @ToString @EqualsAndHashCode public class ResultBean{ private String code; private String message; private T data; public void test1(){ ResultBean r = new ResultBean<>(); r.setCode("200").setData("111"); } } prefix
import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.experimental.Accessors; @Accessors(prefix = 'f') @Data @ToString @EqualsAndHashCode public class ResultBean{ private String fcode; private String fmessage; private T fdata; public void test1(){ ResultBeanr = new ResultBean<>(); r.setCode("200") r.setData("111"); } }