lp-converter-processor 2024年版本迭代匯總

在2024年日常開發(fā)任務(wù)中,通過對(duì)工具的使用,發(fā)現(xiàn)工具的缺陷和對(duì)工具的功能的擴(kuò)展

  1. lp-converter-processor
    描述:代碼轉(zhuǎn)換工具
    文章鏈接: https://blog.csdn.net/wqr503/article/details/125927752

最新版本

<dependency>
    <groupId>com.github.wqr503</groupId>
    <artifactId>lp-converter-processor</artifactId>
    <version>2.0.10</version>
</dependency>

版本描述
a. 兼容Java 9開始,javax.annotationAPI被從 JDK 中移除導(dǎo)致@PostConstruct注解不存在
b. 支持內(nèi)部類解析,實(shí)現(xiàn)多個(gè)@ConverterMapper解析
c. 解決類名相同情況下導(dǎo)致的@Component的加載失敗
b. 拆分接口BeanMerger,能單獨(dú)實(shí)現(xiàn)對(duì)象比對(duì)功能

示范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);
    }
}

如果這篇文章對(duì)你有幫助請(qǐng)給個(gè)star

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容