首页 文章

MyBatis:自动扫描类型别名

提问于
浏览
0

我有一个带有此条目的MyBatis mapper.xml文件:

<select id="findAll"
            resultType="User">
...
</select>

...“User”类在此包中:

com.company.model.User

...在application.properties中我有这个条目:

mybatis.type-aliases-package = com.company.model

一切正常 .

在重构并将一些类移动到子包之后,MyBatis在autoscan期间无法再找到它们 .

包结构现在是这样的:

com.company.entity.users.User
com.company.entity.departments.Department
com.company.entity.students.Student

我尝试过(在许多其他变体中:使用'/'而不是' . ',没有'classpath:'等):

mybatis.type-aliases-package = classpath:com.company.entity.*

但无法使其发挥作用 .

如何告诉MyBatis在包“com.company.entity”包的所有子包下扫描?

1 回答

  • 1

    根据Mybatis configuration,您可以使用分隔符来分隔所需的包 . 这些是分隔符:

    “,; \ t \ n”

    然后你可以通过以下方式设置:

    mybatis.type-aliases-package = com.company.entity.users,com.company.entity.departments,com.company.entity.students
    

相关问题