mapper-locations
顧名思義是一個定義mapper位置的屬性
在yml或properties下配置,作用是實現mapper接口配置見mapper和接口的綁定。
使用場景:
當mapper接口和mapper接口對應的配置文件在
- 命名上相同
- 所在的路徑相同
則mapper-locations可以不用配置,配置也不會生效。
但是,如果
當mapper接口和mapper接口對應的配置文件在
- 命名上不同或
- 所在的路徑不同
之一不同,需要配置mapper-locations才能實現接口的綁定
mapper接口:com.liuzeyu.mapper.UserMapper.java
配置文件:mapper.UserMapper.xml
實現接口綁定需要在配置文件中配置:
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
補充
實現接口綁定還可以在mapper接口上,直接使用註解實現,類似: