Spring Boot整合通用mapper

1.引入依赖


       
           tk.mybatis
           mapper
           4.1.5
       

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 {

}

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);
    }

}

你可能感兴趣的:(Spring Boot整合通用mapper)