第一步,导入tk mybatis依赖
<!-- 通用tk mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
<exclusions>
<!-- 排除spring的自带jdbc -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
第二步,配置mapper接口,继承通用mapper
例如:public interface UserMapper extends Mapper<UmsMember>
第三步,在实体类中配置通用mapper的主键和主键返回策略,添加ID属性中@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
然后在属性上添加注解,例如:
/**账号*/
@Column(name = "username")
private String username;
/**密码*/
@Column(name = "password")
private String password;
第四步,配置spring boot启动类扫描器MapperScan
注解,使用通用mapper的tk.mybatis.spring.annotation.MapperScan
包@MapperScan(basePackages = "com.*.*.*.mapper")