Spring Boot整合通用mapper
2019-10-22 本文已影响0人
月哥说了算
1.引入依赖
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
2.编写表对应的实体类
@Table(name = "users")
public class User implements Serializable {
@Id
private int id;
private String username;
private String password;
private String email;
3.写mapper
/**
* @author :gzy
* @date :Created in 2019/10/22
* @description :
* @version: 1.0
*/
@Service
public interface RoleMapper extends Mapper<User> {
}
4.启动开启扫描通用mappper位置
注意@MapperScan注解引入的包名
package com.guo.lianxi1020;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@MapperScan(basePackages = "com.guo.lianxi1020.dao")
public class Lianxi1020Application {
public static void main(String[] args) {
SpringApplication.run(Lianxi1020Application.class, args);
}
}