简介
可能很多人更熟悉使用xml的方式来使用MyBatis.Spring Boot 也提供了用xml来描述sql的方式.
注解的方式请见上篇:Spring Boot系列之六 以注解方式整合MyBatis
实例
-
目录结构
src/main/resources/mapper 用来存放xxMapper.xml文件
其他省略...
-
pom.xml
-
application.properties
-
MyBatisConfig
这个类是MyBatis的配置类,其中
-
@MapperScan用来配置Spring Boot自动配置功能如何扫描XXMapper.java
-
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml"));用来配置Spring Boot自动配置功能如何扫描xxMapper.xml.
-
-
User
-
UserMapper
-
userMapper.xml
-
logback日志打印sql
测试
代码
本文限于篇幅原因,不能展示所有的代码,如果想要完整的代码示例,请移步:https://github.com/sunshineasbefore/veryjava.spring.boot/tree/master/mybatis-xml
支持请点赞,不喜勿喷.
每天一点点,成长多一点.