SpringBoot环境下使用通用Mapper
环境搭建:
约定的项目结构
约定的配置文件
1,引入SpringBoot的maven依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
引入通用Mapper依赖
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
2,书写配置文件
在resources下建application.properties/.yml/.yaml,
放在dao、service、controller包的同级
3,书写启动类
@SpringBootApplication
@MapperScan(“com.xxx.dao”) //tk.mybatis包下
4,书写实体类
例:
@Table(name = "c_admin")
public class Admin