目录
2.在Springboot的核心配置文件application.properties中配置MyBaits的Mapper.xml文件所在位置:
3.在springboot的核心配置文件application.properties中配置数据源:
4.在Myaits的Mapper接口中添加@Mapper注解或者在运行的主类上添加@MapperScan(com.luluyu.springboot.mapper)注解包扫描
1.在pom.xml中配置相关jar依赖
<!-- 加载mybatis整合springboot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!-- MySQL的jdbc驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
2.在Springboot的核心配置文件application.properties中配置MyBaits的Mapper.xml文件所在位置:
mybaits.mapper-location=class:com/luluyu/springboot/mapper/*.xml
3.在springboot的核心配置文件application.properties中配置数据源:
#配置数据库连接信息
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
4.在Myaits的Mapper接口中添加@Mapper注解或者在运行的主类上添加@MapperScan(com.luluyu.springboot.mapper)注解包扫描