🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 通用Mapper [https://github.com/abel533/Mapper](https://github.com/abel533/Mapper) [https://github.com/abel533/Mapper/wiki/1.3-spring-boot](https://github.com/abel533/Mapper/wiki/1.3-spring-boot) 生成MyBatis单表的增删改查 引入这个mybatis和jdbc都不需要了,他会引入进来 ~~~ <!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter --> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.1.5</version> </dependency> ~~~ 然后继承 ~~~ public interface UserMapper extends Mapper<User> { ~~~ ![](https://img.kancloud.cn/b3/0c/b30c40d6b4a8c0c72467978b74440d73_1916x1400.png) 用mybatis插件,第一次动态生成了 注意,这里要用他的扫描包,不能用springboot的 ~~~ @tk.mybatis.spring.annotation.MapperScan("com.Map") public class BootDemoApplication { ~~~ ~~~ # pojo别名扫描包 mybatis.type-aliases-package=com.pojo # 加载mybatis映射文件, 通用mapper不需要这个 # mybatis.mapper-locations=classpath:mapper/*Mapper.xml ~~~ 常见问题 [https://github.com/abel533/Mapper/wiki/faq](https://github.com/abel533/Mapper/wiki/faq) ~~~ @Data @Table(name = "User") //表名 public class User { @Id //import javax.persistence.Id; @KeySql(useGeneratedKeys = true) private Long id; private String username; @Transient //不是数据库的字段 private String note; } ~~~ 然后使用就行 事务 ~~~ //事务 @Transactional //org.springframework.transaction.annotation.Transactional; public void insertUser(User user) { UserMapper.insert(user); } ~~~