3

mybatis | @Mapper 和 @MapperScan

 1 year ago
source link: https://benpaodewoniu.github.io/2022/11/17/java49/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

@Mapper@MapperScan 都是 mybatis 的注解。

两个注解都是在告诉 mybatis 这里有一个接口类。

@Mapper

但是,有一个问题,就是每一个接口类都要有一个 @Mapper,就会非常麻烦。

@MapperScan

Scan 有浏览的意思,如果在启动类上进行注解

@MapperScan({"com.aop8.emp.mapper","com.aop8.dep.mapper"})

他们就会把上面两个文件夹下面的所有接口类都注册到 mybatis 中。

还支持表达式。

@MapperScan({"com.aop8.*.mapper","com.baidu.*.mapper"})

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK