跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • crud 模板方法
未分類
31 8 月 2020

crud 模板方法

crud 模板方法

資深大佬 : huifer 20

crud template

  • 增删改查模板项目,旨在减少重复代码.

  • 注意: 目前只支持 redis-hash 的数据类型

  • 项目地址: https://github.com/huifer/crud

功能

  • 单个表的数据库增删改查操作
  • 单个表的数据库+缓存的增删改查操作
  • 单个实体的缓存增删改查操作

如何使用

  • 在启动类上添加如下代码
    • daoType 可选项有 mybatis 和 mybatis-plus
    • scanPackages 用来填写需要扫描的实体包路径,支持多个
@EnableCrudTemplate(daoType = DaoType.MYBATIS_PLUS, scanPackages = {     "com.github.huifer.mybatis.plus.mybatis"}) 

mybatis 支持

  • 添加依赖
    <dependency>       <groupId>com.github.huifer</groupId>       <artifactId>for-mybatis</artifactId>       <version>0.0.4-SNAPSHOT</version>     </dependency> 
  • 对 mapper 进行修改
@CacheKey(key = "issues", type = IssuesEntity.class) public interface IssuesMapper extends A<Integer, IssuesEntity> {} 
  • 对实体进行修改
public class IssuesEntity implements BaseEntity {} 

mybatis plus 支持

  • 添加依赖
    <dependency>       <groupId>com.github.huifer</groupId>       <artifactId>for-mybatis-plus</artifactId>       <version>0.0.4-SNAPSHOT</version>     </dependency> 
  • 对 mapper 进行修改
@CacheKey(key = "issues", type = IssuesEntity.class) public interface IssuesMapper extends BaseMapper<IssuesEntity>,     AforMybatisPlus<Integer, IssuesEntity>  
  • 对实体进行修改
public class IssuesEntity implements BaseEntity {} 
  • 调用层 mybatis 和 mybatis-plus 都是同一个入口
  @Autowired   private CrudFacade<IssuesEntity, IntIdInterface<Integer>> crudFacade; 
  • 只需要引入CrudFacade组件就可以拥有数据库+缓存的 crud 操作了. 如果不需要缓存请将 mapper 上的@CacheKey删掉

entity 支持

  • 给实体对象添加注解 @CacheKey
    • redis-hash field 取值说明: idFiled=实体类的某个字段, idMethod=实体类中的一个方法,如果两者同时存在以idMethod为准, 建议填写一个
@CacheKey(key = "tt", type = IssuesEntity.class, idFiled = "newTitle", idMethod = "ooo") public class IssuesEntity  {     private Integer id;   private String newTitle;    private String ooo() {     return "OOO" + this.newTitle;   } } 

Contributers

  • @huifer
  • 希望各位可以发表一下想法、看法
大佬有話說 (0)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具