DataNativeSqlParser支持#{},${}
This commit is contained in:
@@ -20,7 +20,7 @@ import org.redkale.convert.json.JsonConvert;
|
||||
*/
|
||||
public interface DataNativeSqlParser {
|
||||
|
||||
NativeSqlStatement parse(Function<Integer, String> signFunc, String dbtype, String nativeSql, Map<String, Object> params);
|
||||
NativeSqlStatement parse(Function<Integer, String> signFunc, String dbtype, String rawSql, Map<String, Object> params);
|
||||
|
||||
public static class NativeSqlStatement {
|
||||
|
||||
@@ -30,9 +30,6 @@ public interface DataNativeSqlParser {
|
||||
//根据参数值集合重新生成的带?参数可执行的计算总数sql,用于返回Sheet对象
|
||||
protected String nativeCountSql;
|
||||
|
||||
//是否包含InExpression参数名
|
||||
protected boolean existInNamed;
|
||||
|
||||
//需要预编译的参数名, 数量与sql中的?数量一致
|
||||
protected List<String> paramNames;
|
||||
|
||||
@@ -65,14 +62,6 @@ public interface DataNativeSqlParser {
|
||||
this.nativeCountSql = nativeCountSql;
|
||||
}
|
||||
|
||||
public boolean isExistInNamed() {
|
||||
return existInNamed;
|
||||
}
|
||||
|
||||
public void setExistInNamed(boolean existInNamed) {
|
||||
this.existInNamed = existInNamed;
|
||||
}
|
||||
|
||||
public List<String> getParamNames() {
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
@@ -228,6 +228,9 @@ public interface Attribute<T, F> {
|
||||
* @return Attribute对象
|
||||
*/
|
||||
public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldName) {
|
||||
if (Map.class.isAssignableFrom(clazz)) {
|
||||
return (Attribute) map(fieldName);
|
||||
}
|
||||
try {
|
||||
return create(clazz, fieldName, (Class) null, clazz.getDeclaredField(fieldName), (java.lang.reflect.Method) null, (java.lang.reflect.Method) null, null);
|
||||
} catch (NoSuchFieldException | SecurityException ex) {
|
||||
@@ -1161,4 +1164,40 @@ public interface Attribute<T, F> {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Map类生成 Attribute 对象。 fieldName都不能为null
|
||||
*
|
||||
* @param fieldName 字段名
|
||||
*
|
||||
* @return Attribute对象
|
||||
*/
|
||||
public static <T extends Map, F> Attribute<T, F> map(final String fieldName) {
|
||||
return new Attribute<T, F>() {
|
||||
@Override
|
||||
public Class<? extends F> type() {
|
||||
return (Class) Object.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> declaringClass() {
|
||||
return (Class) Map.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String field() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public F get(T obj) {
|
||||
return (F) ((Map) obj).get(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(T obj, F value) {
|
||||
((Map) obj).put(fieldName, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user