or条件sql 示例
This commit is contained in:
parent
4e198d8213
commit
c68faf5914
|
|
@ -1,7 +1,9 @@
|
||||||
package com.czg;
|
package com.czg;
|
||||||
|
|
||||||
|
import com.czg.market.entity.MkLimitTimeDiscount;
|
||||||
import com.mybatisflex.codegen.Generator;
|
import com.mybatisflex.codegen.Generator;
|
||||||
import com.mybatisflex.codegen.config.*;
|
import com.mybatisflex.codegen.config.*;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
@ -10,7 +12,7 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||||
* @author ww
|
* @author ww
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
// private final static String BASE_URL = "rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com";
|
// private final static String BASE_URL = "rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com";
|
||||||
private final static String BASE_URL = "192.168.1.42";
|
private final static String BASE_URL = "192.168.1.42";
|
||||||
private final static String PORT = "3306";
|
private final static String PORT = "3306";
|
||||||
private final static String USERNAME = "root";
|
private final static String USERNAME = "root";
|
||||||
|
|
@ -20,19 +22,24 @@ public class Main {
|
||||||
static String basePackage = "com.czg.";
|
static String basePackage = "com.czg.";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
//or条件sql写法示例
|
||||||
|
// orSqlTest();
|
||||||
|
|
||||||
// tableName 指定需要生成的表
|
|
||||||
|
|
||||||
// String packageName = "system";
|
// String packageName = "system";
|
||||||
// String packageName = "account";
|
// String packageName = "account";
|
||||||
// String packageName = "product";
|
// String packageName = "product";
|
||||||
String packageName = "market";
|
String packageName = "market";
|
||||||
|
// tableName 指定需要生成的表
|
||||||
String tableName = "mk_drainage_config";
|
String tableName = "mk_product_smart_suggest";
|
||||||
String author = "zs";
|
String author = "ww";
|
||||||
//是否生成DTO实体 默认生成
|
//是否生成DTO实体 默认生成
|
||||||
boolean isGenerateDto = false;
|
boolean isGenerateDto = true;
|
||||||
|
|
||||||
|
initTableEntity(packageName, tableName, author, isGenerateDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initTableEntity(String packageName, String tableName, String author, boolean isGenerateDto) {
|
||||||
//配置数据源
|
//配置数据源
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
||||||
|
|
@ -55,7 +62,7 @@ public class Main {
|
||||||
serviceGenerator.generate();
|
serviceGenerator.generate();
|
||||||
|
|
||||||
//默认生成全参数DTO
|
//默认生成全参数DTO
|
||||||
if(isGenerateDto){
|
if (isGenerateDto) {
|
||||||
GlobalConfig dtoConfig = createDtoGlobalConfig(currentWorkingDirectory + "/cash-common/cash-common-service",
|
GlobalConfig dtoConfig = createDtoGlobalConfig(currentWorkingDirectory + "/cash-common/cash-common-service",
|
||||||
basePackage + packageName, "tb", tableName);
|
basePackage + packageName, "tb", tableName);
|
||||||
Generator dtoGenerator = new Generator(dataSource, dtoConfig);
|
Generator dtoGenerator = new Generator(dataSource, dtoConfig);
|
||||||
|
|
@ -64,6 +71,49 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void orSqlTest() {
|
||||||
|
QueryWrapper queryWrapper1 = new QueryWrapper();
|
||||||
|
queryWrapper1.eq(MkLimitTimeDiscount::getId, 2)
|
||||||
|
.or(MkLimitTimeDiscount::getShopId)
|
||||||
|
.gt(25);
|
||||||
|
System.out.println(queryWrapper1.toSQL());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
QueryWrapper queryWrapper3 = new QueryWrapper();
|
||||||
|
queryWrapper3.eq(MkLimitTimeDiscount::getTitle, "王五")
|
||||||
|
.or(wrapper -> {
|
||||||
|
wrapper.lt(MkLimitTimeDiscount::getShopId, 20)
|
||||||
|
.gt(MkLimitTimeDiscount::getId, 100);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
System.out.println(queryWrapper3.toSQL());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
QueryWrapper queryWrapper4 = new QueryWrapper();
|
||||||
|
queryWrapper4.eq(MkLimitTimeDiscount::getTitle, "李四")
|
||||||
|
.or("id BETWEEN ? AND ?", 20, 40);
|
||||||
|
System.out.println(queryWrapper4.toSQL());
|
||||||
|
System.out.println();
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq(MkLimitTimeDiscount::getShopId, 2)
|
||||||
|
.eq(MkLimitTimeDiscount::getIsDel, 0)
|
||||||
|
.orderBy(MkLimitTimeDiscount::getSort).desc()
|
||||||
|
.orderBy(MkLimitTimeDiscount::getUpdateTime).desc();
|
||||||
|
|
||||||
|
queryWrapper.and(q -> {
|
||||||
|
q.eq(MkLimitTimeDiscount::getUseShopType, "all").or(q1 -> {
|
||||||
|
q1.eq(MkLimitTimeDiscount::getUseShopType, "only").eq(MkLimitTimeDiscount::getShopId, 3);
|
||||||
|
}).or(q2 -> {
|
||||||
|
q2.eq(MkLimitTimeDiscount::getUseShopType, "custom").and(q3 -> {
|
||||||
|
q3.eq(MkLimitTimeDiscount::getShopId, 3).or("FIND_IN_SET( " + 3 + ", use_shops ) > 0");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
System.out.println(queryWrapper.toSQL());
|
||||||
|
}
|
||||||
|
|
||||||
public static GlobalConfig createGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
public static GlobalConfig createGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||||
//创建配置内容
|
//创建配置内容
|
||||||
GlobalConfig globalConfig = new GlobalConfig();
|
GlobalConfig globalConfig = new GlobalConfig();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue