lp-converter-processor 2024年版本迭代汇总
在2024年日常开发任务中,通过对工具的使用,发现工具的缺陷和对工具的功能的扩展
- lp-converter-processor
文章链接: 代码转换工具
最新版本
<dependency>
<groupId>com.github.wqr503</groupId>
<artifactId>lp-converter-processor</artifactId>
<version>2.0.10</version>
</dependency>
版本描述
a. 兼容Java 9开始,javax.annotationAPI被从 JDK 中移除导致@PostConstruct注解不存在
b. 支持内部类解析,实现多个@ConverterMapper解析
c. 解决类名相同情况下导致的@Component的加载失败
b. 拆分接口BeanMerger,能单独实现对象比对功能
示范Demo
public interface Test {
@ConverterMapper(implSpringInterface = true)
interface TestInterface extends BeanConverter<TestEntityBI, TestMap.TestEntityB>, CommonJudgeSame {
}
@ConverterMapper(implSpringInterface = true)
interface TestMerger extends BeanMerger<TestEntityBI, TestMap.TestEntityB>, CommonJudgeSame {
}
}
生成代码
@Component("com.ceshi.test.Test.TestInterface")
public class TestInterface_ConverterImpl implements Test.TestInterface {
public TestInterface_ConverterImpl() {
}
public Test.TestMap.TestEntityB convertTo(Test.TestEntityBI param0) {
if (param0 == null) {
return null;
} else {
Test.TestMap.TestEntityB target = new Test.TestMap.TestEntityB();
String field1 = param0.getTestSame();
target.setTestSame(field1);
Integer field2 = param0.getTestName();
target.setTestName(field2);
return (Test.TestMap.TestEntityB)this.postConvertTo(param0, target);
}
}
public MergeResult<Test.TestMap.TestEntityB> mergeTo(Test.TestEntityBI param0, Test.TestMap.TestEntityB param1) {
if (param0 == null) {
return MergeResult.build(param1, (Set)null);
} else {
Set<String> changeFieldNames = new HashSet();
String field1 = param0.getTestSame();
if (!this.judgeSameWithString(field1, param1.getTestSame())) {
param1.setTestSame(field1);
changeFieldNames.add("testSame");
}
Integer field2 = param0.getTestName();
if (!this.judgeSameWithInteger(field2, param1.getTestName())) {
param1.setTestName(field2);
changeFieldNames.add("testName");
}
MergeResult mergeResult = MergeResult.build(param1, changeFieldNames);
return this.postMergeTo(param0, param1, mergeResult);
}
}
@PostConstruct
public void init() {
ConverterHolder.registerConverter(Test.TestInterface.class, this, true);
}
}
@Component("com.ceshi.test.Test.TestMerger")
public class TestMerger_ConverterImpl implements Test.TestMerger {
public TestMerger_ConverterImpl() {
}
public MergeResult<Test.TestMap.TestEntityB> mergeTo(Test.TestEntityBI param0, Test.TestMap.TestEntityB param1) {
if (param0 == null) {
return MergeResult.build(param1, (Set)null);
} else {
Set<String> changeFieldNames = new HashSet();
String field1 = param0.getTestSame();
if (!this.judgeSameWithString(field1, param1.getTestSame())) {
param1.setTestSame(field1);
changeFieldNames.add("testSame");
}
Integer field2 = param0.getTestName();
if (!this.judgeSameWithInteger(field2, param1.getTestName())) {
param1.setTestName(field2);
changeFieldNames.add("testName");
}
MergeResult mergeResult = MergeResult.build(param1, changeFieldNames);
return this.postMergeTo(param0, param1, mergeResult);
}
}
@PostConstruct
public void init() {
ConverterHolder.registerConverter(Test.TestMerger.class, this, true);
}
}
如果这篇文章对你有帮助请给个star