mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-07 17:48:35 +08:00
Merge pull request #133 from lipanre/main
`AutoMappers`、`AutoMappings`、`ReverseAutoMappings` 增加 Repeatable 特性支持
This commit is contained in:
commit
8510a72ea9
@ -0,0 +1,37 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.annotations.ReverseAutoMapping;
|
||||
|
||||
/**
|
||||
* @author lipanre
|
||||
*/
|
||||
@AutoMapper(target = User.class)
|
||||
@AutoMapper(target = UserDto.class)
|
||||
public class UserQuery {
|
||||
|
||||
@AutoMapping(targetClass = User.class, target = "username")
|
||||
@AutoMapping(targetClass = UserDto.class, target = "username")
|
||||
private String name;
|
||||
|
||||
@ReverseAutoMapping(targetClass = User.class, source = "age")
|
||||
@ReverseAutoMapping(targetClass = UserDto.class, source = "age")
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,8 @@
|
||||
package io.github.linpeilie;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.github.linpeilie.model.Goods;
|
||||
import io.github.linpeilie.model.GoodsDto;
|
||||
import io.github.linpeilie.model.GoodsStateEnum;
|
||||
import io.github.linpeilie.model.MapModelA;
|
||||
import io.github.linpeilie.model.User;
|
||||
import io.github.linpeilie.model.UserDto;
|
||||
import io.github.linpeilie.model.UserVO;
|
||||
import io.github.linpeilie.model.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -15,6 +10,8 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class QuickStartTest {
|
||||
@ -146,4 +143,23 @@ public class QuickStartTest {
|
||||
System.out.println(goods1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiMapperDeclareTest() {
|
||||
User user = new User();
|
||||
user.setUsername("testName");
|
||||
user.setAge(12);
|
||||
|
||||
UserQuery userQuery1 = converter.convert(user, UserQuery.class);
|
||||
Assertions.assertEquals("testName", userQuery1.getName());
|
||||
Assertions.assertEquals(12, userQuery1.getAge());
|
||||
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setUsername("testName2");
|
||||
userDto.setAge(18);
|
||||
|
||||
UserQuery userQuery2 = converter.convert(userDto, UserQuery.class);
|
||||
Assertions.assertEquals("testName2", userQuery2.getName());
|
||||
Assertions.assertEquals(18, userQuery2.getAge());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package io.github.linpeilie.annotations;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import org.mapstruct.BeanMapping;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
import org.mapstruct.IterableMapping;
|
||||
@ -23,6 +20,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Repeatable(AutoMappers.class)
|
||||
public @interface AutoMapper {
|
||||
|
||||
Class<?> target();
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package io.github.linpeilie.annotations;
|
||||
|
||||
import io.github.linpeilie.DefaultMapping;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import org.mapstruct.BeanMapping;
|
||||
import org.mapstruct.Condition;
|
||||
import org.mapstruct.Mapper;
|
||||
@ -20,6 +18,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
|
||||
|
||||
@Target({ElementType.FIELD, ElementType.METHOD,ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Repeatable(AutoMappings.class)
|
||||
public @interface AutoMapping {
|
||||
|
||||
Class<?> targetClass() default DefaultMapping.class;
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package io.github.linpeilie.annotations;
|
||||
|
||||
import io.github.linpeilie.DefaultMapping;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import org.mapstruct.BeanMapping;
|
||||
import org.mapstruct.Condition;
|
||||
import org.mapstruct.Mapper;
|
||||
@ -35,6 +33,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Repeatable(ReverseAutoMappings.class)
|
||||
public @interface ReverseAutoMapping {
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user