mybatis.mapper-locations 配置一个或多个mapper.xml路径

Mapper.xml要放在 resources 文件夹下。


子模块之间经常会互相引用,比如user-center模块需要引用common-center模块和tool-center模块,就需要把common-center模块和tool-center的Jar包依赖进来,因为每个项目的包路径不一样,mapper.xml的路径也不一样,这个时候就需要引入多个路径。

common-center项目的mapper.xml 路径在 resources/mappers/push 下面

tool-center项目的mapper.xml 路径在 resources/mappers/下面

那么user-center项目的application.properties配置文件中配置mapper.xml路径如下:

mybatis.mapper-locations=classpath:mappers/push/*.xml,classpath*:/mappers/*.xml

注意点:在classpath后面的 * 必不可少,缺少型号的话后面的通配符不起作用。( **表示可以表示任意多级目录)。


如果是在dao接口类中使用@Select,@Update等增删改查的注解的话,在 yml配置中就不需要 mapper-locations的配置。

不过建议两个都用比较好,像是比较简单的直接注解进行sql,比较复杂的在xml里配置还是比较爽的

发布了134 篇原创文章 · 获赞 26 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/inflaRunAs/article/details/105205624