注解@Mapper、@MapperScan

2019-09-19 11:36:58

参考地址 注解@Mapper、@MapperScan

1、@Mapper注解:

作用:在接口类上添加了@Mapper,在编译之后会生成相应的接口实现类

添加位置:接口类上面


@Mapper

public interface UserDAO {

   //代码

}

1

2

3

4

如果想要每个接口都要变成实现类,那么需要在每个接口类上加上@Mapper注解,比较麻烦,解决这个问题用@MapperScan


2、@MapperScan

作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类

添加位置:是在Springboot启动类上面添加,


@SpringBootApplication

@MapperScan("com.winter.dao")

public class SpringbootMybatisDemoApplication {


    public static void main(String[] args) {

        SpringApplication.run(SpringbootMybatisDemoApplication.class, args);

    }

}

1

2

3

4

5

6

7

8

添加@MapperScan(“com.winter.dao”)注解以后,com.winter.dao包下面的接口类,在编译之后都会生成相应的实现类


3、使用@MapperScan注解多个包

(实际用的时候根据自己的包路径进行修改)


@SpringBootApplication  

@MapperScan({"com.kfit.demo","com.kfit.user"})  

public class App {  

    public static void main(String[] args) {  

       SpringApplication.run(App.class, args);  

    }  

}  

1

2

3

4

5

6

7

4、 如果dao接口类没有在Spring Boot主程序可以扫描的包或者子包下面,可以使用如下方式进行配置:

(没验证过,不确定能否使用,或许需要根据自己定义的包名进行修改路径)


@SpringBootApplication  

@MapperScan({"com.kfit.*.mapper","org.kfit.*.mapper"})  

public class App {  

    public static void main(String[] args) {  

       SpringApplication.run(App.class, args);  

    }  

}  



  • 2018-07-10 16:56:00

    MUI-图片轮播控件

    图片轮播继承自slide插件,因此其DOM结构、事件均和slide插件相同; 在MUI框架中针对图片的轮播做了一个简单的封装。

  • 2018-07-10 16:56:42

    mysql in 排序 也可以按in里面的顺序来排序

    SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我们真要按IN里面的顺序排序怎么办?SQL能不能完成?是否需要取回来后再foreach一下?

  • 2018-08-02 15:03:28

    正则提取字段

    如下文案,如何提取中间的文案呢 eq: 我们的%%aaa%%不一致,哈哈哈 提取后是aaa