依赖
<!-- dto -> domain orika 转换工具 -->
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
</dependency>
package com.ruoyi.common.config;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MapperFacade 用于dto ->entity的转换
*/
实体类
public class Person {
public Person() {
}
public Person(String name, Integer age, Date dateTime) {
this.name = name;
this.age = age;
this.dateTime = dateTime;
}
private String name;
private Integer age;
private Date dateTime;
public String getName() {
return name;
}
public Person setName(String name) {
this.name = name;
return this;
}
public Integer getAge() {
return age;
}
public Person setAge(Integer age) {
this.age = age;
return this;
}
public Date getDateTime() {
return dateTime;
}
public Person setDateTime(Date dateTime) {
this.dateTime = dateTime;
return this;
}
public class Student {
private String name;
private String grade;
private Integer age;
private Date birth;
public Date getBirth() {
return birth;
}
public Student setBirth(Date birth) {
this.birth = birth;
return this;
}
public String getName() {
return name;
}
public Student setName(String name) {
this.name = name;
return this;
}
public String getGrade() {
return grade;
}
public Student setGrade(String grade) {
this.grade = grade;
return this;
}
public Integer getAge() {
return age;
}
public Student setAge(Integer age) {
this.age = age;
return this;
}
使用方式
public class MapperFactoryTest {