Mybatis—学习过程—Mybatis插件之通用mapper
1.什么是通用mapper
2.使用步骤
- 导入依赖
<dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>3.1.2</version> </dependency>
Mybatis全局配置文件中的插件配置
<plugins>
<!--如果有分页插件要放在通用mapper之前-->
<plugin interceptor="com.github.pagehelper">
<property name="dialect" value="mysql"/>
</plugin>
<plugin interceptor="tk.mybatis.mapper.mapperhelper.MapperInterceptor">
<!--指定当前通用mapper接口使用的是哪一个-->
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
</plugin>
</plugins>
//@Table:表示实体和哪个表是映射关系,
//@Id表示对应主键,
//@GeneratedValue(strategy = GenerationType.IDENTITY)主键生成策略
@Table(name = "t_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String username;
}
定义通用mapper
public interface UserMapper extends Mapper<User> {
}