Code Monkey home page Code Monkey logo

crud's Introduction

crud template

  • 增删改查模板项目,旨在减少重复代码.
  • 注意: 目前只支持redis-hash的数据类型

功能

  • 单个表的数据库增删改查操作
  • 单个表的数据库+缓存的增删改查操作
  • 单个实体的缓存增删改查操作
  • 对象比较
  • Id增强查询

如何使用

  • 在启动类上添加如下代码
    • scanPackages 用来填写需要扫描的实体包路径,支持多个
    • 填写相关mapper方法名称.
@EnableCrudTemplate(
    scanPackages = {
        "com.github.huifer.mybatis"},
    selectByIdMethodName = "selectByPrimaryKey",
    deleteByIdMethodName = "deleteByPrimaryKey",
    updateByIdMethodName = "updateByPrimaryKeySelective",
    insertMethodName = "insertSelective")

mybatis+mybatis-plus 支持

  • 添加依赖
    <dependency>
      <groupId>com.github.huifer</groupId>
      <artifactId>common</artifactId>
      <version>LAST_VERSION</version>
    </dependency>
  • 对mapper进行修改
@CacheKey(key = "issues", type = IssuesEntity.class)
public interface IssuesMapper  {}
  • 对实体进行修改
public class IssuesEntity implements BaseEntity {}
  • 对实体进行修改
public class IssuesEntity implements BaseEntity {}
  • 调用层 mybatis 和 mybatis-plus 都是同一个入口
  @Autowired
  private CrudFacade 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

License

  • Apache License 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.