mapstruct 多参数用法
时间: 2023-11-03 22:00:43 浏览: 46
MapStruct提供了多种多参数的用法。可以使用@Mapping注解的source属性指定要映射的源属性,target属性指定要映射的目标属性。例如:
@Mapping(source = "sourceProperty1", target = "targetProperty1")
@Mapping(source = "sourceProperty2", target = "targetProperty2")
void map(Source source);
还可以使用@Mapping注解的expression属性指定一个表达式来进行映射。例如:
@Mapping(expression = "java(source.getProperty1() + source.getProperty2())", target = "targetProperty")
void map(Source source);
同时,可以在映射方法上使用多个@Mapping注解来指定不同的映射方式。例如:
@Mapping(source = "sourceProperty1", target = "targetProperty1")
@Mapping(source = "sourceProperty2", target = "targetProperty2")
void map1(Source source);
@Mapping(expression = "java(source.getProperty1() + source.getProperty2())", target = "targetProperty")
void map2(Source source);
以上是MapStruct的一些多参数用法,可以根据具体需求来选择适合的方式进行映射。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)