java注解枚举转换器,SpringBoot -生成Entity和Dto互转的双向枚举类 -使用注解@Mapper(componentModel = "spring")...

1.导入pom文件 ,版本号自定

org.mapstruct

mapstruct-jdk8

1.2.0.CR1

org.mapstruct

mapstruct-processor

1.2.0.CR1

provided

2.举例编写Training的双向枚举类TrainingConverter

import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")

public interface TrainingConverter {

Training dtoToEntity(TrainingDto trainingDto);

TrainingDto entityToDto(Training training);

List listEntityToDto(List training);

//pageEntityToDto也是支持的

// listEntityToDto 也支持

}

3.在maven工程结构的root 项下,如图操作maven clean和compile 操作

b01b095d2f2125a455994dec12775d12.png

4.已自动生成了相应的TrainingConverterImpl类

5572632e14b36a939b3f875f799883b7.png

f755d25441cf793c98389f23a5e37fc9.png

5.自动生成的实现类位置在target/generated-sources/annotations 的同级目录下

b9d837ad0810a5acf7c86c64d3b11efa.png

6.更多的生成的方法,参考下面的博客

7. 手动指定@Mappings的对应 , source对应转换源的字段的字段的字段, target对应目标类的字段

93066154d8c1f68b035239adc0e024d5.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值