review code.
This commit is contained in:
@@ -13,10 +13,13 @@ import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
|||||||
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
|
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
|
||||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
import com.orion.lang.constant.Const;
|
import com.orion.lang.constant.Const;
|
||||||
|
import com.orion.lang.utils.ext.yml.YmlExt;
|
||||||
import com.orion.ops.framework.mybatis.domain.BaseDO;
|
import com.orion.ops.framework.mybatis.domain.BaseDO;
|
||||||
import com.orion.ops.framework.mybatis.mapper.IMapper;
|
import com.orion.ops.framework.mybatis.mapper.IMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jiahang Li
|
* @author Jiahang Li
|
||||||
*/
|
*/
|
||||||
@@ -25,14 +28,16 @@ public class CodeGenerator {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String outputDir = "D:/MP/";
|
String outputDir = "D:/MP/";
|
||||||
String author = Const.ORION_AUTHOR;
|
String author = Const.ORION_AUTHOR;
|
||||||
String url = "jdbc:mysql://127.0.0.1:3306/orion-ops-pro?characterEncoding=utf8";
|
|
||||||
String username = "root";
|
|
||||||
String password = "Data@123456";
|
|
||||||
|
|
||||||
// 表名
|
// 表名
|
||||||
String[] tables = {"user_info"};
|
String[] tables = {"user_info"};
|
||||||
// 模块
|
// 模块
|
||||||
String module = "user";
|
String module = "user";
|
||||||
|
// 连接
|
||||||
|
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
||||||
|
YmlExt yaml = YmlExt.load(yamlFile);
|
||||||
|
String url = yaml.getValue("spring.datasource.druid.url");
|
||||||
|
String username = yaml.getValue("spring.datasource.druid.username");
|
||||||
|
String password = yaml.getValue("spring.datasource.druid.password");
|
||||||
|
|
||||||
// 执行
|
// 执行
|
||||||
runGenerator(outputDir, author,
|
runGenerator(outputDir, author,
|
||||||
@@ -140,11 +145,11 @@ public class CodeGenerator {
|
|||||||
// 映射文件的包
|
// 映射文件的包
|
||||||
.xml("mapper")
|
.xml("mapper")
|
||||||
// service接口的包
|
// service接口的包
|
||||||
.service("ignore.service")
|
.service("service")
|
||||||
// serviceImpl接口的包
|
// serviceImpl接口的包
|
||||||
.serviceImpl("ignore.service.impl")
|
.serviceImpl("service.impl")
|
||||||
// controller接口的包
|
// controller接口的包
|
||||||
.controller("ignore.controller")
|
.controller("controller")
|
||||||
// 构建
|
// 构建
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -156,7 +161,7 @@ public class CodeGenerator {
|
|||||||
.strategy(stConfig)
|
.strategy(stConfig)
|
||||||
// 整合包名策略
|
// 整合包名策略
|
||||||
.packageInfo(pkConfig)
|
.packageInfo(pkConfig)
|
||||||
// TODO 自定义convert文件
|
// TODO 自定义convert文件 request VO
|
||||||
// .injection()
|
// .injection()
|
||||||
// TODO 自定义模板以及convert文件
|
// TODO 自定义模板以及convert文件
|
||||||
// .template()
|
// .template()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package com.orion.ops.framework.mybatis.cache;
|
package com.orion.ops.framework.mybatis.query;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.orion.lang.define.wrapper.Store;
|
import com.orion.lang.define.wrapper.Store;
|
||||||
import com.orion.lang.utils.Valid;
|
import com.orion.lang.utils.Valid;
|
||||||
|
import com.orion.ops.framework.mybatis.cache.RowCacheHolder;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ public class CacheQuery<T> {
|
|||||||
|
|
||||||
private Serializable id;
|
private Serializable id;
|
||||||
|
|
||||||
|
private boolean force;
|
||||||
|
|
||||||
private CacheQuery(BaseMapper<T> dao, Serializable id) {
|
private CacheQuery(BaseMapper<T> dao, Serializable id) {
|
||||||
this.dao = dao;
|
this.dao = dao;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -50,6 +53,16 @@ public class CacheQuery<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制查询
|
||||||
|
*
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public CacheQuery<T> force() {
|
||||||
|
this.force = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <R> R get(Class<R> c) {
|
public <R> R get(Class<R> c) {
|
||||||
T row = this.get();
|
T row = this.get();
|
||||||
@@ -60,12 +73,15 @@ public class CacheQuery<T> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T get() {
|
public T get() {
|
||||||
Class<? extends BaseMapper<T>> mapperClass = (Class<? extends BaseMapper<T>>) dao.getClass();
|
Class<? extends BaseMapper<T>> mapperClass = (Class<? extends BaseMapper<T>>) dao.getClass();
|
||||||
|
// 不查询缓存
|
||||||
|
if (!force) {
|
||||||
// 从缓存中获取
|
// 从缓存中获取
|
||||||
Store<T> store = RowCacheHolder.get(mapperClass, id);
|
Store<T> store = RowCacheHolder.get(mapperClass, id);
|
||||||
// 设置过缓存
|
// 设置过缓存
|
||||||
if (store != null) {
|
if (store != null) {
|
||||||
return store.get();
|
return store.get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 查询
|
// 查询
|
||||||
T row = dao.selectById(id);
|
T row = dao.selectById(id);
|
||||||
// 设置缓存
|
// 设置缓存
|
||||||
@@ -20,8 +20,18 @@ public class Conditions {
|
|||||||
* @param <T> T
|
* @param <T> T
|
||||||
* @return wrapper
|
* @return wrapper
|
||||||
*/
|
*/
|
||||||
public static <T> LambdaQueryWrapper<T> validateWrapper() {
|
public static <T> LambdaQueryWrapper<T> wrapper() {
|
||||||
return new ValidateLambdaWrapper<>();
|
return new ValidateLambdaWrapper<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件有效性验证 wrapper
|
||||||
|
*
|
||||||
|
* @param <T> T
|
||||||
|
* @return wrapper
|
||||||
|
*/
|
||||||
|
public static <T> LambdaQueryWrapper<T> wrapper(Class<T> clazz) {
|
||||||
|
return new ValidateLambdaWrapper<>(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,17 @@ import java.util.Collection;
|
|||||||
*/
|
*/
|
||||||
public class ValidateLambdaWrapper<T> extends LambdaQueryWrapper<T> {
|
public class ValidateLambdaWrapper<T> extends LambdaQueryWrapper<T> {
|
||||||
|
|
||||||
|
public ValidateLambdaWrapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidateLambdaWrapper(T entity) {
|
||||||
|
super(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidateLambdaWrapper(Class<T> entityClass) {
|
||||||
|
super(entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 有效性验证
|
* 有效性验证
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user