美文网首页
Spring Boot整合通用mapper

Spring Boot整合通用mapper

作者: 月哥说了算 | 来源:发表于2019-10-22 21:00 被阅读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);
        }
    
    }
    

    相关文章

      网友评论

          本文标题:Spring Boot整合通用mapper

          本文链接:https://www.haomeiwen.com/subject/jfucvctx.html