我有这样的状况:
class Person {
String firstName;
String lastName;
Integer age;
Float height;
//seters, getters, etc.
}
class PersonDto{
String name; // it should be: firstName + " " + lastName
Integer personAge;
Float height;
}
如何映射Person
-> PersonDto
与所有字段?
答案 0 :(得分:3)
您可以使用:
mapperFactory.classMap(Person.class, PersonDTO.class)
.field("age","personAge")
.byDefault()
.customize(
new CustomMapper<Person, PersonDTO> {
public void mapAtoB(Person a, PersonDTO b, MappingContext context) {
b.setName(a.getFirstName()+ " "+a.getLastName());
}
})
.register();