All Projects → yidasanqian → dynamic-add-date

yidasanqian / dynamic-add-date

Licence: MIT license
一款基于MyBatis框架,可以对插入和更新Sql语句动态地添加日期列和对应值的插件

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to dynamic-add-date

Java Spring Web
OpenTracing Spring Web instrumentation
Stars: ✭ 89 (+85.42%)
Mutual labels:  interceptor
Sieppari
Small, fast, and complete interceptor library for Clojure/Script
Stars: ✭ 133 (+177.08%)
Mutual labels:  interceptor
Okhttp Json Mock
Mock your datas for Okhttp and Retrofit in json format in just a few moves
Stars: ✭ 231 (+381.25%)
Mutual labels:  interceptor
Interceptors
Low-level HTTP/HTTPS/XHR/fetch request interception library.
Stars: ✭ 100 (+108.33%)
Mutual labels:  interceptor
Chucker
🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device)
Stars: ✭ 2,169 (+4418.75%)
Mutual labels:  interceptor
Examples
Examples of Mock Service Worker usage with various frameworks and libraries.
Stars: ✭ 163 (+239.58%)
Mutual labels:  interceptor
Geheimtur
a secret door to your Pedestal application
Stars: ✭ 74 (+54.17%)
Mutual labels:  interceptor
go-grpcmw
A Go package and protobuf generator for managing grpc interceptors.
Stars: ✭ 19 (-60.42%)
Mutual labels:  interceptor
Androidsnooper
Android library to record the network calls through the interceptor mechanism of the http clients.
Stars: ✭ 132 (+175%)
Mutual labels:  interceptor
Component
🔥🔥🔥A powerful componentized framework.一个强大、100% 兼容、支持 AndroidX、支持 Kotlin并且灵活的组件化框架
Stars: ✭ 2,434 (+4970.83%)
Mutual labels:  interceptor
Ng Http Interceptor
Http Interceptor library for Angular
Stars: ✭ 108 (+125%)
Mutual labels:  interceptor
Fresh
🍋 A token refresh library for Dart.
Stars: ✭ 128 (+166.67%)
Mutual labels:  interceptor
Interceptor
A browser extension to mock AJAX requests at the browser level
Stars: ✭ 182 (+279.17%)
Mutual labels:  interceptor
Agentframework
An elegant & efficient TypeScript metaprogramming API to build software agents
Stars: ✭ 97 (+102.08%)
Mutual labels:  interceptor
esa-httpclient
An asynchronous event-driven HTTP client based on netty.
Stars: ✭ 82 (+70.83%)
Mutual labels:  interceptor
Hooman
http interceptor to hoomanize cloudflare requests
Stars: ✭ 82 (+70.83%)
Mutual labels:  interceptor
Spring Boot Examples
个人学习 SpringBoot2.x 写的一些示例程序,目前正在持续更新中.....
Stars: ✭ 159 (+231.25%)
Mutual labels:  interceptor
ionic4-angular7-httpinterceptor-example
Ionic 4 and Angular 7 Tutorial: HTTP Interceptor Example
Stars: ✭ 15 (-68.75%)
Mutual labels:  interceptor
python-grpc-demo
Python + gRPC demos
Stars: ✭ 135 (+181.25%)
Mutual labels:  interceptor
Arouter
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Stars: ✭ 13,587 (+28206.25%)
Mutual labels:  interceptor

dynamic-add-date

Build Status Maven Central

Dynamic-add-date是基于Mybatis插件原理开发的可以动态在InsertUpdate Sql语句中添加日期列和对应的值的插件。

可以解决MySQL 5.6.5之前的版本对自动初始化时间戳的限制:

  • DATETIME列不支持DEFAULT CURRENT_TIMESTAMPON UPDATE CURRENT_TIMESTAMP
  • DEFAULT CURRENT_TIMESTAMPON UPDATE CURRENT_TIMESTAMP每张表最多可以使用在一个TIMESTAMP列上而且不能和另一个TIMESTAMP列一起使用。

要求

  • 支持jdk7及之后的版本
  • MySql

功能

  • 自定义要生成的日期列的名称
  • 自动处理原始Sql语句中已包含自定义日期列名
  • 支持插入、更新、批量插入和批量更新Sql语句日期列的生成
  • 支持INSERT INTO SELECT语句
  • 支持忽略表,表名支持正则表达式

在你的应用中添加Dynamic-add-date

添加下面的依赖到你的pom文件中:

<dependency>
    <groupId>io.github.yidasanqian</groupId>
    <artifactId>dynamic-add-date</artifactId>
    <version>1.1.0</version>
</dependency>

若使用Gradle/Grails:

compile 'io.github.yidasanqian:dynamic-add-date:1.1.0'

然后在mybatis-config.xml配置文件中加入如下设置即可:

<plugins>
        <plugin interceptor="io.github.yidasanqian.dynamicadddate.AddDateInterceptor">
        </plugin>
</plugins>

例如,原始Sql为:

insert into user(name, profession) values(?, ?)

使用该插件后Sql语句为:

insert into user(name, profession, gmt_create, gmt_modified) values(?, ?, '2017-10-15 10:10:10', '2017-10-15 10:10:10')

批量插入的情况:

insert into user(name, profession) values(?, ?), (?, ?), (?, ?)

使用该插件后Sql语句为:

insert into user(name, profession, gmt_create, gmt_modified) values(?, ?, '2017-10-15 10:10:10', '2017-10-15 10:10:10'),
(?, ?, '2017-10-15 10:10:10', '2017-10-15 10:10:10'), (?, ?, '2017-10-15 10:10:10', '2017-10-15 10:10:10')

支持INSERT INTO SELECT语句

原始sql:

insert into t_user(username, mobile, create_at)
       select r.`name`, ?, r.create_at from t_role r;

使用该插件后Sql语句为:

INSERT INTO t_user (username, mobile, create_at, update_at) SELECT r.`name`, ?, '2019-07-06 10:36:51.066', '2019-07-06 10:36:51.066' FROM t_role r

默认新建日期的列名为 gmt_create, 更新日期的列名为 gmt_modified

可以通过设置key createDateColumnNameupdateDateColumnName来分别指定日期列的名称:

<plugin interceptor="io.github.yidasanqian.dynamicadddate.AddDateInterceptor">
    <property name="createDateColumnName" value="gmt_create"/>
    <property name="updateDateColumnName" value="gmt_modified"/>
</plugin>

与Spring Boot集成

首先mybatis依赖

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.4</version>
</dependency>

其次写入自定义配置:

1)xml方式进行配置
也是在mybatis-config.xml配置文件中加入如下设置:

 <plugin interceptor="io.github.yidasanqian.dynamicadddate.AddDateInterceptor">
     <property name="createDateColumnName" value="gmt_create"/>
     <property name="updateDateColumnName" value="gmt_modified"/>
 </plugin>

然后在 application.properties加入如下配置即可:

mybatis.config-location=classpath:mybatis-config.xml

2)创建bean方式进行配置

@Bean
public AddDateInterceptor addDateInterceptor(){
    Properties properties = new Properties();
    properties.setProperty("createDateColumnName","gmt_create");
    properties.setProperty("updateDateColumnName","gmt_modified");
    AddDateInterceptor addDateInterceptor = new AddDateInterceptor();
    addDateInterceptor.setProperties(properties);
    return addDateInterceptor;
}

忽略表

实际应用中并不是所有的表都需要创建时间和更新时间字段,如何设置忽略处理的表呢?

1)xml方式
也是在mybatis-config.xml配置文件中加入如下设置:

<plugins>
    <plugin interceptor="io.github.yidasanqian.dynamicadddate.AddDateInterceptor">
        <property name="ignoreTables" value="^user.*,permission"/>
    </plugin>
</plugins>

2)创建Bean方式

@Bean
public AddDateInterceptor addDateInterceptor(){
    Properties properties = new Properties();
    properties.setProperty("createDateColumnName","gmt_create");
    properties.setProperty("updateDateColumnName","gmt_modified");
    properties.setProperty("ignoreTables","^user.*,permission");
    AddDateInterceptor addDateInterceptor = new AddDateInterceptor();
    addDateInterceptor.setProperties(properties);
    return addDateInterceptor;
}

其中name=ignoreTables属性值为固定,不能变,value的格式:表名,表名

其中value的值为表名,支持正则表达式,且多个表名以英文逗号,分隔并且之间不含空格。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].