1.自动生成set,get方法
pom.xml:
<!-- 工具类 Java get set 自动生成 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
在实体类上加上@Data注解
2.自动生成拷贝对象
<properties>
<java.version>1.8</java.version>
<org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
</properties>
<!-- 工具类 Java bean mappings -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<!--<version>1.2.0</version>-->
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
后台代码:
import com.oem.entity.Oem_prd_lot;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Created by ghost on 2019/3/8.
*/
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface FbpretboxMapper {
FbpretboxMapper INSTANCE = Mappers.getMapper(FbpretboxMapper.class);
LotInfo getLotInfo(Oem_prd_lot lot);
List<LotInfo> getLotInfo(List<Oem_prd_lot> list);
}
使用方法:
LotInfo lot = FbpretboxMapper.INSTANCE.getLotInfo(oem_prd_lot);