标签:ace under lag esc source dom ringbuf sys trim
忽略批量生成的前提
暴力书写insertUtil
从navicat 中复制 insert语句 至此传入
import java.util.Arrays;
import java.util.List;
/**
* @author zs
* @date 2019/7/30
*/
public class InsertUtils {
public static String createInsertSql(String string) {
// 删除所有
final String sub = string.replaceAll("`", "");
StringBuffer stringBuffer = new StringBuffer();
final String subedString = stringBuffer.append(sub.substring(0, sub.indexOf("o") + 1)).append(" ").append(sub.substring(sub.indexOf(".") + 1, sub.indexOf("values")+6)).toString();
String substring = subedString.substring(subedString.indexOf("(")+1, subedString.indexOf(")"));
List<String> list = Arrays.asList(substring.split(","));
String head = subedString.substring(0, subedString.indexOf("values"));
String sqlWord = "";
StringBuffer sb = new StringBuffer();
sb.append(head).append(" ").append("values").append(" ").append("(").append(" ");
for (int i = 0; i < list.size(); i++) {
if (list.get(i).contains("_")){
sqlWord = deleteUnderline(list.get(i));
}else {
sqlWord = list.get(i).trim();
}
if (i == list.size()-1){
sb.append("#{").append(sqlWord).append("}").append(" ");
}else {
sb.append("#{").append(sqlWord).append("}").append(",").append(" ");
}
// System.out.println(sb.toString());
}
sb.append(")").append(";");
return sb.toString();
}
private static String deleteUnderline(String domian) {
StringBuffer sb = new StringBuffer();
final String[] strings = domian.split("_");
for (int i = 0; i < strings.length; i++) {
if (i >0){
final char[] chars = strings[i].toCharArray();
chars[0] = (char) (chars[0] - 32);
strings[i] = new String(chars);
}
sb.append(strings[i]);
}
return sb.toString().trim();
}
public static void main(String[] args) {
String s ="insert into `closet`.`auth_resource` ( `biz_id`, `res_id`, `res_name`, `res_type`, `parent_res_id`, `res_description`, `res_path`, `res_url`, `remark`, `delete_flag`, `create_user`, `create_time`, `update_user`, `update_time`) values ( ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘, ‘‘);";
String insertSql = InsertUtils.createInsertSql(s);
System.out.println(insertSql);
}
}
标签:ace under lag esc source dom ringbuf sys trim
原文地址:https://www.cnblogs.com/senjiang/p/11273491.html