一、添加pom依赖jar包:
1 <!--整合mybatis--> 2 <dependency> 3 <groupId>org.mybatis.spring.boot</groupId> 4 <artifactId>mybatis-spring-boot-starter</artifactId> 5 <version>1.1.1</version> 6 </dependency> 7 8 <!-- 超高性能连接池 --> 9 <dependency> 10 <groupId>com.zaxxer</groupId> 11 <artifactId>HikariCP-java6</artifactId> 12 <version>2.3.9</version> 13 <scope>compile</scope> 14 </dependency>
二、项目结构:
Mapper文件在resources目录下。并在SpringBoot入口类中添加 @MapperScan("cn.com.venus.oa.mapper") @ServletComponentScan 注解
在入口类上添加注解,配置Mapper接口的地址
1 @ServletComponentScan 2 @MapperScan("cn.com.venus.oa.mapper") 3 public class venusAppcliation { 4 ... 5 }
@ServletComponentScan: 设置启动时spring能够扫描到我们自己编写的servlet和filter
@MapperScan: 用于扫描的mapper接口
在yml配置文件中:
1 spring: 2 datasource: 3 driver-class-name: com.mysql.jdbc.Driver 4 url: jdbc:mysql:///venus 5 username: root 6 password: admin 7 8 mvc: 9 view: 10 prefix: /WEB-INF/pages/ 11 suffix: .jsp 12 13 mybatis: 14 type-aliases-package: cn.com.venus.oa.pojo 15 config-location: classpath:/mybatis/mybatis-config.xml 16 mapper-locations: classpath:/mybatis/mappers/*.xml
时间: 2024-12-21 22:42:15