or条件sql 示例
This commit is contained in:
parent
4e198d8213
commit
c68faf5914
|
|
@ -1,7 +1,9 @@
|
|||
package com.czg;
|
||||
|
||||
import com.czg.market.entity.MkLimitTimeDiscount;
|
||||
import com.mybatisflex.codegen.Generator;
|
||||
import com.mybatisflex.codegen.config.*;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
|
@ -20,19 +22,24 @@ public class Main {
|
|||
static String basePackage = "com.czg.";
|
||||
|
||||
public static void main(String[] args) {
|
||||
//or条件sql写法示例
|
||||
// orSqlTest();
|
||||
|
||||
// tableName 指定需要生成的表
|
||||
|
||||
// String packageName = "system";
|
||||
// String packageName = "account";
|
||||
// String packageName = "product";
|
||||
String packageName = "market";
|
||||
|
||||
String tableName = "mk_drainage_config";
|
||||
String author = "zs";
|
||||
// tableName 指定需要生成的表
|
||||
String tableName = "mk_product_smart_suggest";
|
||||
String author = "ww";
|
||||
//是否生成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();
|
||||
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
||||
|
|
@ -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) {
|
||||
//创建配置内容
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
|
|
|||
Loading…
Reference in New Issue