Spring Boot系列之七 以xml整合MyBatis

简介

可能很多人更熟悉使用xml的方式来使用MyBatis.Spring Boot 也提供了用xml来描述sql的方式.

注解的方式请见上篇:Spring Boot系列之六 以注解方式整合MyBatis

实例

  • 目录结构

src/main/resources/mapper 用来存放xxMapper.xml文件

其他省略...

  • pom.xml

Spring Boot系列之七 以xml整合MyBatis

  • application.properties

Spring Boot系列之七 以xml整合MyBatis

  • MyBatisConfig

这个类是MyBatis的配置类,其中

    • @MapperScan用来配置Spring Boot自动配置功能如何扫描XXMapper.java

    • sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml"));用来配置Spring Boot自动配置功能如何扫描xxMapper.xml.

Spring Boot系列之七 以xml整合MyBatis

  • User

Spring Boot系列之七 以xml整合MyBatis

  • UserMapper

Spring Boot系列之七 以xml整合MyBatis

  • userMapper.xml

Spring Boot系列之七 以xml整合MyBatis

  • logback日志打印sql

Spring Boot系列之七 以xml整合MyBatis

测试

Spring Boot系列之七 以xml整合MyBatis

代码

本文限于篇幅原因,不能展示所有的代码,如果想要完整的代码示例,请移步:https://github.com/sunshineasbefore/veryjava.spring.boot/tree/master/mybatis-xml

支持请点赞,不喜勿喷.

每天一点点,成长多一点.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值