目录
1.实体类和映射类只加注解@Data
2.将@Data换成getter和setter后build
3.那么此时我把getter和setter换成lombok的getter和setter
1.实体类和映射类只加注解@Data
映射关系类
这个时候运行
提示源参数中不存在
注意这个文件夹
2.将@Data换成getter和setter后build
package com.zsp.quartz.entity;
public class Qa {
private String myName;
private String userAge;
public Qa() {
}
public Qa(String myName, String userAge) {
this.myName = myName;
this.userAge = userAge;
}
public String getMyName() {
return myName;
}
public void setMyName(String myName) {
this.myName = myName;
}
public String getUserAge() {
return userAge;
}
public void setUserAge(String userAge) {
this.userAge = userAge;
}
}
package com.zsp.quartz.entity;
public class QaDto {
private String nameVo;
private String userAge;
@Override
public String toString() {
return "QaDto{" +
"nameVo='" + nameVo + '\'' +
", userAge='" + userAge + '\'' +
'}';
}
public String getNameVo() {
return nameVo;
}
public void setNameVo(String nameVo) {
this.nameVo = nameVo;
}
public String getUserAge() {
return userAge;
}
public void setUserAge(String userAge) {
this.userAge = userAge;
}
public QaDto() {
}
public QaDto(String nameVo, String userAge) {
this.nameVo = nameVo;
this.userAge = userAge;
}
}
此时文件夹生成了UserMapStructImpl
进入之后带代码如下,重写了我映射关系类的接口,并对属性进行赋值,采用的是getter,setter方法。
package com.zsp.quartz.entity;
import javax.annotation.Generated;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-08-23T10:13:53+0800",
comments = "version: 1.2.0.Final, compiler: javac, environment: Java 1.8.0_321 (Oracle Corporation)"
)
@Component
public class UserMapStructImpl implements UserMapStruct {
@Override
public QaDto toDto(Qa qa) {
if ( qa == null ) {
return null;
}
QaDto qaDto = new QaDto();
qaDto.setUserAge( qa.getUserAge() );
qaDto.setNameVo( qa.getMyName() );
return qaDto;
}
}
此时我再运行
运行成功
我把target文件夹删掉后重新运行测试代码,发现又生成了这个Impl文件。
3.那么此时我把getter和setter换成lombok的getter和setter
将target也先删掉
重新运行测试类
运行报错
看一下target文件夹
并没有那个实现类Impl
暂时找不到问题出在哪里,为了不报错还是老老实实的getter和setter吧。