【问题标题】:How migrate mybatis mapper from Java to Kotlin in spring?spring 如何将 mybatis mapper 从 Java 迁移到 Kotlin?
【发布时间】:2021-06-04 15:07:50
【问题描述】:

我有带有 MyBatis ORM 的 spring-boot 应用程序。在java中我写喜欢

@Mapper
@Repository
public interface FooMapper {

    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "resultFoo", value = {
            @Result(property = "rowId", column = "ROW_ID"),
            @Result(property = "created", column = "CREATED"),
            @Result(property = "lastUpdated", column = "LAST_UPD"),
            @Result(property = "fooId", column = "FOO_ID"),
    })
    Foo findBy(SelectStatementProvider selectStatement);

    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(value = {
            @Result(property = "rowId", column = "ROW_ID"),
            @Result(property = "created", column = "CREATED"),
            @Result(property = "lastUpdated", column = "LAST_UPD"),
            @Result(property = "fooId", column = "FOO_ID"),
    })
    List<Foo> findListBy(SelectStatementProvider selectStatement);

    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(value = {
            @Result(property = "fooId", column = "FOO_ID")
    })
    List<String> findFooListBy(SelectStatementProvider selectStatement);

    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "record.rowId", keyColumn = "row_id")
    int insert(InsertStatementProvider<Foo> insertStatement);

    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);
}

这很好用!

但我需要将我的所有应用程序都转换为 Kotlin。 我尝试了以下代码:

@Mapper
@Repository
interface FooMapper {
    @SelectProvider(type = SqlProviderAdapter::class, method = "select")
    @Results(
        id = "resultReferralActivation",
        value = [Result(property = "rowId", column = "ROW_ID"), Result(
            property = "created",
            column = "CREATED"
        ), Result(property = "lastUpdated", column = "LAST_UPD"), Result(
            property = "fooId",
            column = "FOO_ID"
        )]
    )
    fun findBy(selectStatement: SelectStatementProvider?): Foo?

    @SelectProvider(type = SqlProviderAdapter::class, method = "select")
    @Results(
        value = [Result(property = "rowId", column = "ROW_ID"), Result(
            property = "created",
            column = "CREATED"
        ), Result(property = "lastUpdated", column = "LAST_UPD"), Result(
            property = "fooId",
            column = "FOO_ID"
        )]
    )
    fun findListBy(selectStatement: SelectStatementProvider?): List<Foo?>?

    @SelectProvider(type = SqlProviderAdapter::class, method = "select")
    @Results(value = [Result(property = "fooId", column = "FOO_ID")])
    fun findFooListBy(selectStatement: InsertStatementProvider?): List<String?>?

    @InsertProvider(type = SqlProviderAdapter::class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "record.rowId", keyColumn = "row_id")
    fun insert(insertStatement: InsertStatementProvider<Foo?>?): Int

    @UpdateProvider(type = SqlProviderAdapter::class, method = "update")
    fun update(updateStatement: UpdateStatementProvider?): Int
}

但它不起作用。如果我在 java 中尝试使用 awtowired FooMapper 或 kotlin 类应用程序失败,并显示如下消息:找不到 bean FooMapper。如果我评论了我的自动装配尝试,应用程序就会启动,但是当我检查 spring-bean-list 时,我发现 bean FooMapper 不存在。

如何将我的 java 映射器转换为 Konlin?

感谢您的帮助!

【问题讨论】:

标签: java spring-boot kotlin mybatis spring-mybatis


【解决方案1】:

问题在于“想法”如何创建文件夹。 当我手动创建配置映射器搜索配置的正确文件夹结构时,一切正常

【讨论】:

    猜你喜欢
    • 2018-03-25
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多