优化代码

master
星期八 6 years ago
parent 3c6a3f3d78
commit 1e56db8fe6
  1. 1
      panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java
  2. 8
      panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java
  3. 8
      panda-jdbc/src/main/java/org/panda/jdbc/sql/MysqlBuilder.java

@ -93,7 +93,6 @@ public abstract class AbstractDbBuiler {
sql=sql.toLowerCase();
if (sql.lastIndexOf("order")>sql.lastIndexOf(")")){
sb.append(sql.substring(sql.indexOf("from")+4,sql.lastIndexOf("order")));
}else{
sb.append(sql.substring(sql.indexOf("from")+4));
}

@ -15,6 +15,8 @@ import java.util.Map;
*/
public class BeanSqlUtil {
public static final String SQL_CHARACTER = "_";
/**
* 大小写转化驼峰
* @param str
@ -23,13 +25,13 @@ public class BeanSqlUtil {
public static String caseToHump(String str){
StringBuffer strBuffer=new StringBuffer();
char[] charArray=str.toCharArray();
for (int i=0;i<charArray.length;i++){
for (int i=0,charArrayLenght=charArray.length;i<charArrayLenght;i++){
if (i==0){
strBuffer.append(charArray[i]);
continue;
}
if (Character.isUpperCase(charArray[i])){
strBuffer.append("_"+charArray[i]);
strBuffer.append(SQL_CHARACTER+charArray[i]);
}else {
strBuffer.append(charArray[i]);
}
@ -46,7 +48,7 @@ public class BeanSqlUtil {
StringBuffer strBuffer=new StringBuffer();
char[] charArray=str.toCharArray();
for (int i=0;i<charArray.length;i++){
if (charArray[i] == '_'){
if (SQL_CHARACTER.equals(charArray[i])){
i++;
strBuffer.append(Character.toUpperCase(charArray[i]));
}else {

@ -81,12 +81,9 @@ public class MysqlBuilder extends AbstractDbBuiler {
}
});
}
map.forEach((key,value)->{
sql.append(createTableStr(value));
});
return sql.toString();
}
@ -122,7 +119,7 @@ public class MysqlBuilder extends AbstractDbBuiler {
sql.append(",");
}
sql.append("primary key(id)");
sql.append(")ENGINE=MyISAM DEFAULT CHARSET=utf8;");
sql.append(")ENGINE=Innodb DEFAULT CHARSET=utf8;");
return sql.toString();
}
@ -139,7 +136,8 @@ public class MysqlBuilder extends AbstractDbBuiler {
if (CollectionUtil.isEmpty(fieldMap)){
LOGGER.error("can not insert entity:fieldMap is empty");
return null;
throw new RuntimeException("can not insert entity:fieldMap is empty");
// return null;
}
String sql = "INSERT INTO "+ BeanSqlUtil.beanNameToTableName(entityClass);
StringBuilder columns = new StringBuilder("(");

Loading…
Cancel
Save