1. Add dependencies

< the dependency > < groupId > org. Mapstruct < / groupId > < artifactId > mapstruct - jdk8 < / artifactId > < version > 1.2.0. CR1 < / version > </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> < version > 1.2.0. CR1 < / version > < scope > provided < / scope > < / dependency >Copy the code

2. How to use it

// Define the conversion interface
@Mapper(componentModel = "spring")
public interface UserConver {
        UserVo convert(User user); 
    }
    
    
/ / use
   class Cxx{
   
    @Autowired
    private UserConver userConver;
    
    public void convert(a){
        / / conversionUserVo userVo = userConver.convert(user); }}Copy the code

3. Mapping entities

@Mapper(componentModel = "spring")
public interface UserConver {
 
    @Mappings({ @Mapping(source = "id",target = "idUser"), @Mapping(source = "title",target = "title"), @Mapping(source = "pricez",target = "pricez") })
    UserVo item2Dto(User user);
}
Copy the code