init project v1.0.0
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
package com.central.db.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 自定义填充公共 name 字段
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2018/12/11
|
||||
*/
|
||||
public class DateMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
/**
|
||||
* 插入填充,字段为空自动填充
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
Object createTime = getFieldValByName("createTime", metaObject);
|
||||
Object updateTime = getFieldValByName("updateTime", metaObject);
|
||||
if (createTime == null || updateTime == null) {
|
||||
Date date = new Date();
|
||||
if (createTime == null) {
|
||||
setFieldValByName("createTime", date, metaObject);
|
||||
}
|
||||
if (updateTime == null) {
|
||||
setFieldValByName("updateTime", date, metaObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新填充
|
||||
*
|
||||
* @param metaObject
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
//mybatis-plus版本2.0.9+
|
||||
setFieldValByName("updateTime", new Date(), metaObject);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.central.db.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
/**
|
||||
* mybatis-plus配置
|
||||
* @author zlt
|
||||
* @date 2018/12/13
|
||||
*/
|
||||
@Import(DateMetaObjectHandler.class)
|
||||
public class DefaultMybatisPlusConfig {
|
||||
/**
|
||||
* 分页插件,自动识别数据库类型
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印 sql,性能分析拦截器,不建议生产使用
|
||||
* 设置 dev test 环境开启
|
||||
*/
|
||||
@Bean
|
||||
@Profile({"dev","test"})
|
||||
public PerformanceInterceptor performanceInterceptor() {
|
||||
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
|
||||
return performanceInterceptor;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.central.db.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* mapper 父类,注意这个类不要让 mp 扫描到!!
|
||||
* @author zlt
|
||||
*/
|
||||
public interface SuperMapper<T> extends BaseMapper<T> {
|
||||
// 这里可以放一些公共的方法
|
||||
}
|
||||
Reference in New Issue
Block a user