尽管心里会感觉这是好货色, 但一旦应用就开始滑向了技术不通用的死亡深渊…
- the Cloak of Invisibility(隐身衣) ==> lombok(隐形加成)
- the Resurrection Stone(复活石) ==> mapstruct(高效映射)
- the Elder Wand(老魔杖) ==> vavr(链式攻打)
-
@code
- https://github.com/service-ja…
- https://github.com/service-ja…
Lombok
- 注解模式来简化打消臃肿Java代码
- @doc https://projectlombok.org/fea…
- @code https://github.com/rzwitserlo…
// @myself 2020-04-06
以前谁不必Lombok, 我感觉谁是sb...
当初我竟然开始厌弃Lombok这一类“乖僻”的工具了
我可真是一个善变的男人
// IDEA要装置lombok插件
@Setter
@Getter
@Data
@Accessor(chain=true)
@Builder
@ToString -> 输入
@Log(这是一个泛型注解,具体有很多种形式)
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@NonNull
@Cleanup
@ToString
@RequiredArgsConstructor
@Value
@SneakyThrows
@Synchronized
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
Teacher teacher = Teacher.builder().job("teacher").name("teacher").career("teach").build();
Student student = new Student().setJob("student").setHobby("study").setName("student");
Console.log(student);
// teacher(source) -> student(target)
BeanUtils.copyProperties(teacher, student);
Console.log(student);
Lombok-实际 @demo
-
Lombok应用
- https://blog.csdn.net/motui/a…
Lombok-常见问题 @faq
- 常见问题
// lombok在IDEA 中配置有效
// IntelliJ IDEA 应用 lombok 缩小简短代码 @nice https://www.jianshu.com/p/f26d177b88be
1) 装置plugins>lombok
2) annotation process
3) 重启idea @attention
4) 将lombok.config 放在java目录下
// lombok.accessors.chain=true
===
// @accessor(chain=true)生效
@Getter
@Setter
@Accessors(chain = true)
getter setter办法也用正文 不能被笼罩
- 继承上的坑?? @faq
然而如果只应用了@Data,而不应用@EqualsAndHashCode(callSuper=true)的话,
会默认是@EqualsAndHashCode(callSuper=false),
这时候生成的equals()办法只会比拟子类的属性,不会思考从父类继承的属性,
无论父类属性拜访权限是否凋谢
mapstruct
- Java bean mappings
- @code https://github.com/mapstruct/…
- @doc https://mapstruct.org/
Dozer @old
- @code https://github.com/DozerMappe…
用来两个对象之间属性转换的工具 --> copyProperties ??
要写xml??
Dozer-实际
-
Dozer的应用
- https://blog.csdn.net/lp84031…
VAVR
- lambda加强, 元组等
- @code https://github.com/vavr-io/vavr
VAVR-实际
-
VAVR:颠覆你的 Java 体验 @todo
- @blog https://blog.cc1234.cc/
- @doc https://juejin.im/post/5f1d57…
参考
-
大话后端开发的奇淫技巧大汇合 @nice @digest
- https://juejin.im/post/5b07c6…
- @blog https://github.com/SFLAQiu/we…
-
你真的会写Java吗? @nice
- @by https://github.com/lrwinx
- 聊聊clean code https://tech.meituan.com/clea…
- @doc https://juejin.im/entry/59ae0…
// IDE
eclipse -> IDEA !!!
// 命名
com.xxx.domain -> com.xxx.entity
// 工具
应用lombok
DTO转化的时候始终应用set进行属性赋值时, 应用浅拷贝办法?
// 设计模式
设计模式: 所有的模式并不是凭空想象进去的,都是基于重构
// 业务
业务驱动技术 > 技术驱动业务
// 模式
结对编程
多回头看本人的代码
勤于重构
// 源码
多看成熟框架的源码
// UML
UML就是你谈话的语言
类图
时序图
===
// BeanUtils.copyProperties
public interface DTOConvert<S,T> {
T convert(S s);
}
public class UserInputDTOConvert implements DTOConvert {
@Override
public User convert(UserInputDTO userInputDTO) {
User user = new User();
BeanUtils.copyProperties(userInputDTO,user);
return user;
}
}
User user = new UserInputDTOConvert().convert(userInputDTO);
发表回复