注解@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);  

    }  

}  



  • 2021-01-15 13:30:21

    MongoDb web 用户界面

    MongoDB 的 Web 界面访问端口比服务的端口多1000。 如果你的MongoDB运行端口使用默认的27017,你可以在端口号为28017访问web用户界面,即地址为:http://localhost:28017。

  • 2021-01-16 09:31:14

    Xcode两种引入图片的方法

    如果是纯代码,图片名需要手动添加@2x,@3x等倍数标识,且需要指明后缀.png,.jpg;IB添加图片的话只需要指明后缀就好,不用添加倍数标识。

  • 2021-01-16 09:39:32

    iOS 更改状态栏、导航栏颜色,电池颜色

    注意事项,两种方法设置View controller-based status bar appearance 的值不一样,并且如果你的plist里面没有View controller-based status bar appearance,你需要新建一个。然后就可以成功了。

  • 2021-01-16 09:45:19

    tabbar的titlePositionAdjustment设置文字距离

    指定相应的数据去偏移一个位置,向右或者向下为正值,向左或者向上为负值,不过首先你得有一个相对位置的坐标。而tabbarItem文字的坐标是底部为x轴,y轴则是tabbarItem的centerX;