mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
add RawValue
This commit is contained in:
parent
461300eaf7
commit
56c399725b
@ -151,6 +151,10 @@ public class QueryCondition implements Serializable {
|
|||||||
else if (value instanceof QueryWrapper) {
|
else if (value instanceof QueryWrapper) {
|
||||||
sql.append("(").append(dialect.buildSelectSql((QueryWrapper) value)).append(")");
|
sql.append("(").append(dialect.buildSelectSql((QueryWrapper) value)).append(")");
|
||||||
}
|
}
|
||||||
|
//原生sql
|
||||||
|
else if (value instanceof RawValue){
|
||||||
|
sql.append(((RawValue) value).getContext());
|
||||||
|
}
|
||||||
//正常查询,构建问号
|
//正常查询,构建问号
|
||||||
else {
|
else {
|
||||||
appendQuestionMark(sql);
|
appendQuestionMark(sql);
|
||||||
@ -180,7 +184,8 @@ public class QueryCondition implements Serializable {
|
|||||||
if (LOGIC_IS_NULL.equals(logic)
|
if (LOGIC_IS_NULL.equals(logic)
|
||||||
|| LOGIC_IS_NOT_NULL.equals(logic)
|
|| LOGIC_IS_NOT_NULL.equals(logic)
|
||||||
|| value instanceof QueryColumn
|
|| value instanceof QueryColumn
|
||||||
|| value instanceof QueryWrapper) {
|
|| value instanceof QueryWrapper
|
||||||
|
|| value instanceof RawValue) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -95,4 +95,8 @@ public class QueryMethods {
|
|||||||
return select(new StringQueryColumn("1"));
|
return select(new StringQueryColumn("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RawValue raw(String raw){
|
||||||
|
return new RawValue(raw);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.mybatisflex.core.query;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class RawValue implements Serializable {
|
||||||
|
|
||||||
|
private String context;
|
||||||
|
|
||||||
|
public RawValue() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RawValue(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -226,6 +226,38 @@ public class AccountSqlTester {
|
|||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJoin2Sql() {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select()
|
||||||
|
.from(ACCOUNT)
|
||||||
|
.leftJoin(ARTICLE).on(
|
||||||
|
ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID).and(ACCOUNT.AGE.eq(18))
|
||||||
|
)
|
||||||
|
.where(ACCOUNT.AGE.ge(10));
|
||||||
|
|
||||||
|
IDialect dialect = new CommonsDialectImpl();
|
||||||
|
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||||
|
System.out.println(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJoin3Sql() {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select()
|
||||||
|
.from(ACCOUNT)
|
||||||
|
.leftJoin(
|
||||||
|
select().from(ARTICLE).where(ARTICLE.ID.ge(100))
|
||||||
|
).as("a").on(
|
||||||
|
ACCOUNT.ID.eq(raw("a.id"))
|
||||||
|
)
|
||||||
|
.where(ACCOUNT.AGE.ge(10));
|
||||||
|
|
||||||
|
IDialect dialect = new CommonsDialectImpl();
|
||||||
|
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||||
|
System.out.println(sql);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderBySql() {
|
public void testOrderBySql() {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user