Giter Club home page Giter Club logo

mybatis-generator-plugin's Introduction

mybatis-generator-plugin

###实现SaaS模式下的适用于多租户情况的SQL自动生成

<T> T selectByLogicIdAndTenantId(@Param("tenantId") String tenantId,@Param("logicId") String logicId);
int updateByPrimaryKeySelective(@Param("tenantId") String tenantId,@Param("logicId") String logicId);

示例:

  1. 假设需要生成的表结构如下
CREATE TABLE `dict_detail` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  `tenant_id` varchar(64) NOT NULL COMMENT '租户ID',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `state` varchar(32) DEFAULT 'ONLINE' COMMENT '状态',
  `remark` varchar(1024) DEFAULT NULL COMMENT '备注',
  `detail_id` varchar(64) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典明细表';
  1. 在mybatis generator config文件中添加插件的配置
<plugin type="cc.mikaka.mybatis.generator.plugin.SelectByLogicIdAndTenantIdPlugin"/>
<plugin type="cc.mikaka.mybatis.generator.plugin.UpdateByLogicIdAndTenantIdSelectivePlugin"/>
  1. 在mybatis generator config文件中添加表数据的配置
<table tableName="dict_detail">
    <property name="tableTenantId" value="tenant_id"/>
    <property name="tableLogicId" value="detail_id"/>
</table>
  1. 其余配置根据需要变更,然后运行Main

mybatis-generator-plugin's People

Watchers

 avatar  avatar

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.