mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-08 01:58:55 +08:00
commit
3f7038f143
@ -12,15 +12,13 @@
|
||||
<module>quick-start</module>
|
||||
<module>spring-boot</module>
|
||||
<module>spring-boot-with-lombok</module>
|
||||
<!-- <module>spring-boot-3</module>-->
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mapstruct.version>1.5.1.Final</mapstruct.version>
|
||||
<mapstruct-plus.version>1.1.1</mapstruct-plus.version>
|
||||
<spring-boot.version>2.7.0</spring-boot.version>
|
||||
<mapstruct-plus.version>1.1.2</mapstruct-plus.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
</properties>
|
||||
|
||||
@ -41,13 +39,6 @@
|
||||
<artifactId>mapstruct-plus</artifactId>
|
||||
<version>${mapstruct-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@ -56,25 +47,4 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-processor</artifactId>
|
||||
<version>${mapstruct-plus.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -25,8 +25,30 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.9.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-processor</artifactId>
|
||||
<version>${mapstruct-plus.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -15,18 +15,6 @@ public class QuickStart {
|
||||
|
||||
UserDto userDto = converter.convert(user, UserDto.class);
|
||||
System.out.println(userDto); // UserDto{username='jack', age=23, young=false}
|
||||
|
||||
assert user.getUsername().equals(userDto.getUsername());
|
||||
assert user.getAge() == userDto.getAge();
|
||||
assert user.isYoung() == userDto.isYoung();
|
||||
|
||||
User newUser = converter.convert(userDto, User.class);
|
||||
|
||||
System.out.println(newUser); // User{username='jack', age=23, young=false}
|
||||
|
||||
assert user.getUsername().equals(newUser.getUsername());
|
||||
assert user.getAge() == newUser.getAge();
|
||||
assert user.isYoung() == newUser.isYoung();
|
||||
}
|
||||
|
||||
}
|
||||
@ -4,6 +4,7 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.annotations.AutoMappings;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -19,7 +20,7 @@ public class User {
|
||||
private boolean young;
|
||||
|
||||
@AutoMapping(targetClass = UserDto.class, target = "educations", expression = "java(java.lang.String.join(\",\", source.getEducationList()))")
|
||||
private List<String> educationList;
|
||||
private List<String> educationList = new ArrayList<>();
|
||||
|
||||
@AutoMappings({
|
||||
@AutoMapping(targetClass = UserDto.class, target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss"),
|
||||
|
||||
83
example/spring-boot-3/pom.xml
Normal file
83
example/spring-boot-3/pom.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>example</artifactId>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-boot-3</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-processor</artifactId>
|
||||
<version>${mapstruct-plus.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package io.github.linpeilie;
|
||||
|
||||
import io.github.linpeilie.model.Car;
|
||||
import io.github.linpeilie.model.CarDto;
|
||||
import io.github.linpeilie.model.CarType;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class StartUp
|
||||
implements InitializingBean {
|
||||
|
||||
private Converter converter;
|
||||
|
||||
@Autowired
|
||||
public void setConverter(final Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
final Car car = new Car();
|
||||
car.setType(CarType.OTHER);
|
||||
|
||||
final CarDto carDto = converter.convert(car, CarDto.class);
|
||||
System.out.println(carDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package io.github.linpeilie;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class StringToListStringConverter {
|
||||
|
||||
public static List<String> stringToListString(String str) {
|
||||
return Arrays.asList(str.split(","));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import lombok.Data;
|
||||
|
||||
@AutoMapper(target = CarDto.class)
|
||||
@Data
|
||||
public class Car {
|
||||
|
||||
private String make;
|
||||
private SeatConfiguration seatConfiguration;
|
||||
private CarType type;
|
||||
|
||||
@AutoMapping(target = "wheels", ignore = true)
|
||||
private Wheels wheels;
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CarDto {
|
||||
private String make;
|
||||
private SeatConfigurationDto seatConfiguration;
|
||||
private String type;
|
||||
private List<WheelDto> wheels;
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
public enum CarType {
|
||||
SPORTS, OTHER
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Goods {
|
||||
|
||||
private String price;
|
||||
|
||||
private String takeDownTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMapper(target = Goods.class)
|
||||
public class GoodsDto {
|
||||
|
||||
@AutoMapping(target = "takeDownTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date takeDownTime;
|
||||
|
||||
@AutoMapping(target = "price", numberFormat = "$#.00")
|
||||
private int price;
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapMapper;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMapMapper
|
||||
public class MapModelA {
|
||||
|
||||
private String str;
|
||||
private int i1;
|
||||
private Long l2;
|
||||
private MapModelB mapModelB;
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapMapper;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMapMapper
|
||||
public class MapModelB {
|
||||
|
||||
private Date date;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMapper(target = SeatConfigurationDto.class)
|
||||
public class SeatConfiguration {
|
||||
private int numberOfSeats;
|
||||
private SeatMaterial seatMaterial;
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SeatConfigurationDto {
|
||||
private int seatCount;
|
||||
private String material;
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
public enum SeatMaterial {
|
||||
LEATHER, FABRIC
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.annotations.AutoMappings;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = UserDto.class),
|
||||
@AutoMapper(target = UserVO.class)
|
||||
})
|
||||
public class User {
|
||||
|
||||
private String username;
|
||||
|
||||
private int age;
|
||||
private boolean young;
|
||||
|
||||
@AutoMapping(targetClass = UserDto.class, target = "educations", expression = "java(java.lang.String.join(\",\", source.getEducationList()))")
|
||||
private List<String> educationList;
|
||||
|
||||
@AutoMappings({
|
||||
@AutoMapping(targetClass = UserDto.class, target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss"),
|
||||
@AutoMapping(targetClass = UserVO.class, target = "birthday", ignore = true)
|
||||
})
|
||||
private Date birthday;
|
||||
|
||||
@AutoMapping(targetClass = UserDto.class, target = "assets", numberFormat = "$0.00")
|
||||
private double assets;
|
||||
|
||||
@AutoMapping(target = "money", numberFormat = "$0.00")
|
||||
private double money;
|
||||
|
||||
@AutoMappings({
|
||||
@AutoMapping(targetClass = UserVO.class, target = "voField")
|
||||
})
|
||||
private String voField;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.StringToListStringConverter;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AutoMapper(target = User.class, uses = StringToListStringConverter.class)
|
||||
public class UserDto {
|
||||
|
||||
private String username;
|
||||
private int age;
|
||||
private boolean young;
|
||||
|
||||
@AutoMapping(target = "educationList")
|
||||
private String educations;
|
||||
|
||||
private String birthday;
|
||||
|
||||
private String assets;
|
||||
|
||||
private String money;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserVO {
|
||||
|
||||
private String username;
|
||||
|
||||
private int age;
|
||||
private boolean young;
|
||||
|
||||
private List<String> educationList;
|
||||
|
||||
private Date birthday;
|
||||
|
||||
private double assets;
|
||||
|
||||
private String voField;
|
||||
|
||||
private String money;
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
@AutoMapper(target = WheelDto.class)
|
||||
@Data
|
||||
public class Wheel {
|
||||
private WheelPosition position;
|
||||
private int diameter;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WheelDto {
|
||||
private String position;
|
||||
private int diameter;
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
public enum WheelPosition {
|
||||
LEFT_FRONT,
|
||||
RIGHT_FRONT,
|
||||
LEFT_REAR,
|
||||
RIGHT_REAR
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Wheels implements Iterable<Wheel> {
|
||||
private List<Wheel> wheelsList = new ArrayList<>();
|
||||
|
||||
public List<Wheel> getWheelsList() {
|
||||
return wheelsList;
|
||||
}
|
||||
|
||||
public void setWheelsList(List<Wheel> wheelsList) {
|
||||
this.wheelsList = wheelsList;
|
||||
}
|
||||
|
||||
public void add(final Wheel wheel) {
|
||||
wheelsList.add(wheel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Wheel> iterator() {
|
||||
return getWheelsList().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super Wheel> action) {
|
||||
getWheelsList().forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<Wheel> spliterator() {
|
||||
return getWheelsList().spliterator();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,138 @@
|
||||
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.MapModelA;
|
||||
import io.github.linpeilie.model.User;
|
||||
import io.github.linpeilie.model.UserDto;
|
||||
import io.github.linpeilie.model.UserVO;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class QuickStartTest {
|
||||
|
||||
@Autowired
|
||||
private Converter converter;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Map<String, Object> mapModel1 = new HashMap<>();
|
||||
mapModel1.put("str", "1jkf1ijkj3f");
|
||||
mapModel1.put("i1", 111);
|
||||
mapModel1.put("l2", 11231);
|
||||
|
||||
Map<String, Object> mapModel2 = new HashMap<>();
|
||||
mapModel2.put("date", DateUtil.parse("2023-02-23 01:03:23"));
|
||||
|
||||
mapModel1.put("mapModelB", mapModel2);
|
||||
|
||||
final MapModelA mapModelA = converter.convert(mapModel1, MapModelA.class);
|
||||
System.out.println(mapModelA); // MapModelA(str=1jkf1ijkj3f, i1=111, l2=11231, mapModelB=MapModelB(date=2023-02-23 01:03:23))
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void ueseTest() {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setEducations("1,2,3");
|
||||
|
||||
final User user = converter.convert(userDto, User.class);
|
||||
System.out.println(user.getEducationList()); // [1, 2, 3]
|
||||
|
||||
assert user.getEducationList().size() == 3;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void numberFormatTest() {
|
||||
GoodsDto goodsDto = new GoodsDto();
|
||||
goodsDto.setPrice(9);
|
||||
|
||||
final Goods goods = converter.convert(goodsDto, Goods.class);
|
||||
|
||||
System.out.println(goods.getPrice()); // $9.00
|
||||
|
||||
assert "$9.00".equals(goods.getPrice());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateFormatTest() throws ParseException {
|
||||
final GoodsDto goodsDto = new GoodsDto();
|
||||
|
||||
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
final String dateString = "2023-02-23 23:27:37";
|
||||
final Date date = simpleDateFormat.parse(dateString);
|
||||
|
||||
goodsDto.setTakeDownTime(date);
|
||||
|
||||
final Goods goods = converter.convert(goodsDto, Goods.class);
|
||||
|
||||
System.out.println(goods.getTakeDownTime()); // 2023-02-23 23:27:37
|
||||
|
||||
assert dateString.equals(goods.getTakeDownTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionFormatTest() {
|
||||
User user = new User();
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
user.setEducationList(list);
|
||||
|
||||
final UserDto userDto = converter.convert(user, UserDto.class);
|
||||
System.out.println(userDto.getEducations());
|
||||
|
||||
assert "1,2,3".equals(userDto.getEducations());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiClassConvertTest() {
|
||||
User user = new User();
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
user.setEducationList(list);
|
||||
|
||||
user.setUsername("Nick");
|
||||
user.setAge(12);
|
||||
user.setYoung(true);
|
||||
user.setBirthday(DateUtil.parseDateTime("2023-02-23 02:01:43"));
|
||||
user.setAssets(123.234);
|
||||
user.setVoField("vofieldfff");
|
||||
user.setMoney(12543.123);
|
||||
|
||||
final UserVO userVo = converter.convert(user, UserVO.class);
|
||||
System.out.println(userVo);
|
||||
assert user.getUsername().equals(userVo.getUsername());
|
||||
assert user.getAge() == userVo.getAge();
|
||||
assert user.isYoung() == userVo.isYoung();
|
||||
assert userVo.getBirthday() == null;
|
||||
assert user.getAssets() == userVo.getAssets();
|
||||
assert user.getVoField().equals(userVo.getVoField());
|
||||
assert userVo.getMoney().equals("$12543.12");
|
||||
|
||||
final UserDto userDto = converter.convert(user, UserDto.class);
|
||||
System.out.println(userDto);
|
||||
|
||||
assert user.getUsername().equals(userDto.getUsername());
|
||||
assert user.getAge() == userDto.getAge();
|
||||
assert user.isYoung() == userDto.isYoung();
|
||||
assert userDto.getEducations().equals("1,2,3");
|
||||
assert userDto.getBirthday().equals("2023-02-23 02:01:43");
|
||||
assert userDto.getAssets().equals("$123.23");
|
||||
assert userDto.getMoney().equals("$12543.12");
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,6 +17,18 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -17,6 +17,18 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -32,5 +44,25 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-processor</artifactId>
|
||||
<version>${mapstruct-plus.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -16,7 +16,7 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring-boot.version>2.4.5</spring-boot.version>
|
||||
<spring-boot.version>2.7.9</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -17,7 +17,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<mapstruct-plus.version>1.1.1</mapstruct-plus.version>
|
||||
<mapstruct-plus.version>1.1.2</mapstruct-plus.version>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user