com.feingto.cloud.data.jdbc.DataTransform Maven / Gradle / Ivy
package com.feingto.cloud.data.jdbc;
import com.feingto.cloud.kit.json.JSON;
import com.google.common.collect.Maps;
import org.springframework.util.StringUtils;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 数据转换
*
* @author longfei
*/
public class DataTransform {
public static String mergeSql(String sql, String[] field, String[] value) {
Map paramsMap = Maps.newHashMap();
if (field != null && field.length > 0 && value != null && value.length > 0) {
for (int i = 0; i < field.length; i++) {
paramsMap.put(field[i], value[i]);
}
}
return mergeSql(sql, paramsMap);
}
public static String mergeSql(String sql, Map paramsMap) {
String regex = "\\{#(\\S+)#\\}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(sql);
while (matcher.find()) {
String name = matcher.group(1);
if (StringUtils.hasText(paramsMap.get(name))) {
sql = sql.replace("{#" + name + "#}", paramsMap.get(name));
}
}
return sql;
}
public static String toJSON(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy