1、添加pom依赖:
<!--数据库 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
2、application.properties配置问价增加相关配置:
#配置数据源
spring.datasource.url=jdbc:mysql://localhost:3306/msp?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#mybatis配置
mybatis.mapper-locations=classpath*:mapper/*.xml
#开启mybatis数据库字段带下划线,映射支持java类属性驼峰命名
mybatis.configuration.map-underscore-to-camel-case=true
3、启动类增加注解:
@ComponentScan(basePackages = "com.summer.msp.*")//自定义spring boot启动是的扫描路径,避免引用模块无法被扫描到
@MapperScan("com.summer.msp.*.mapper")//配置文件自动扫描制定位置的Mapper接口,然后自动生成代理类,实现接口内容