两个类之间的转换 | MapstructPlus
io.github.linpeilie
mapstruct-plus-spring-boot-starter
${mapstruct-plus.version}
(81条消息) @EqualsAndHashCode(callSuper = true/false) 作用_equalsandhashcode callsuper_ldj2020的博客-CSDN博客
@AutoMapper(target = SysUser.class)
package com.xie.system.domain.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xie.system.domain.SysUser;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @作者:xie
* @时间:2023/7/6 22:28
*/
@Data
@AutoMapper(target = SysUser.class)
public class SysUserVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 用户ID
*/
private Long userId;
/**
* 部门ID
*/
private Long deptId;
/**
* 用户账号
*/
private String userName;
/**
* 用户昵称
*/
private String nickName;
/**
* 用户类型(sys_user系统用户)
*/
private String userType;
/**
* 用户邮箱
*/
private String email;
/**
* 手机号码
*/
private String phonenumber;
/**
* 用户性别(0男 1女 2未知)
*/
private String sex;
/**
* 头像地址
*/
private Long avatar;
/**
* 密码
*/
@JsonIgnore
@JsonProperty
private String password;
/**
* 帐号状态(0正常 1停用)
*/
private String status;
/**
* 最后登录IP
*/
private String loginIp;
/**
* 最后登录时间
*/
private Date loginDate;
/**
* 备注
*/
private String remark;
/**java
* 创建时间
*/
private Date createTime;
}
io.github.linpeilie.ConvertException: cannot find converter from SysUserVo to SysUserio.github.linpeilie.ConvertException: cannot find converter from SysUserVo to SysUser
出现这种报错
查看taget里面有没有io.github.linpeilie编译的的东西没有就是忘记加关于build的东西
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<version>${maven-compiler-plugin.verison}version>
<configuration>
<source>${java.version}source>
<target>${java.version}target>
<encoding>${project.build.sourceEncoding}encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<version>${lombok.version}version>
path>
<path>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-configuration-processorartifactId>
<version>${spring-boot.version}version>
path>
<path>
<groupId>io.github.linpeiliegroupId>
<artifactId>mapstruct-plus-processorartifactId>
<version>${mapstruct-plus.version}version>
path>
<path>
<groupId>org.projectlombokgroupId>
<artifactId>lombok-mapstruct-bindingartifactId>
<version>${mapstruct-plus.lombok.version}version>
path>
annotationProcessorPaths>
<compilerArgs>
<arg>-parametersarg>
compilerArgs>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-surefire-pluginartifactId>
<version>${maven-surefire-plugin.version}version>
<configuration>
<groups>${profiles.active}groups>
<excludedGroups>excludeexcludedGroups>
configuration>
plugin>
<plugin>
<groupId>org.codehaus.mojogroupId>
<artifactId>flatten-maven-pluginartifactId>
<version>${flatten-maven-plugin.version}version>
<configuration>
<updatePomFile>trueupdatePomFile>
<flattenMode>resolveCiFriendliesOnlyflattenMode>
configuration>
<executions>
<execution>
<id>flattenid>
<phase>process-resourcesphase>
<goals>
<goal>flattengoal>
goals>
execution>
<execution>
<id>flatten.cleanid>
<phase>cleanphase>
<goals>
<goal>cleangoal>
goals>
execution>
executions>
plugin>
plugins>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<filtering>falsefiltering>
resource>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>application*include>
<include>bootstrap*include>
<include>banner*include>
includes>
<filtering>truefiltering>
resource>
resources>
build>
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package io.github.linpeilie;
import com.xie.system.domain.SysClient;
import com.xie.system.domain.SysClientToSysClientVoMapper;
import com.xie.system.domain.SysUser;
import com.xie.system.domain.SysUserToSysUserVoMapper;
import com.xie.system.domain.vo.SysClientVo;
import com.xie.system.domain.vo.SysClientVoToSysClientMapper;
import com.xie.system.domain.vo.SysUserVo;
import com.xie.system.domain.vo.SysUserVoToSysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
public class ConvertMapperAdapter {
@Autowired
@Lazy
private SysUserVoToSysUserMapper sysUserVoToSysUserMapper;
@Autowired
@Lazy
private SysClientVoToSysClientMapper sysClientVoToSysClientMapper;
@Autowired
@Lazy
private SysUserToSysUserVoMapper sysUserToSysUserVoMapper;
@Autowired
@Lazy
private SysClientToSysClientVoMapper sysClientToSysClientVoMapper;
public ConvertMapperAdapter() {
}
public SysUser com_xie_system_domain_vo_SysUserVoToSysUser(SysUserVo param) {
return (SysUser)this.sysUserVoToSysUserMapper.convert(param);
}
public SysClient com_xie_system_domain_vo_SysClientVoToSysClient(SysClientVo param) {
return (SysClient)this.sysClientVoToSysClientMapper.convert(param);
}
public SysUserVo com_xie_system_domain_SysUserToSysUserVo(SysUser param) {
return (SysUserVo)this.sysUserToSysUserVoMapper.convert(param);
}
public SysClientVo com_xie_system_domain_SysClientToSysClientVo(SysClient param) {
return (SysClientVo)this.sysClientToSysClientVoMapper.convert(param);
}
}
@GetMapping("/mapstruct")
public R<Void> sendSimpleMessage1() {
SysUserVo admin = sysUserMapper.selectUserByUserName("admin");
SysUser convert = MapstructUtils.convert(admin, SysUser.class);
return R.ok(Objects.requireNonNull(convert).toString());
}
参考地址