Spring Boot之Mybatis

1.引入依赖。mysql、mybatis-spring-boot-starter。
2.配置数据库。
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

3.在启动类中添加对mapper包扫描@MapperScan ,注意直接写包名就行,不用写通配符。
4.开发mapper类

5.在属性文件中配置mybatis的配置文件的路径
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

6.配置文件

7.将mapper类当成普通类使用

原文地址:https://www.cnblogs.com/zd540/p/11281755.html