消除魔法值

master
星期八 5 years ago
parent 3821b1bdef
commit afb036a2ca
  1. 8
      src/main/java/com/lq/code/util/HttpKit.java
  2. 7
      src/main/java/com/lq/code/util/sql/AbstractDbBuiler.java

@ -23,6 +23,10 @@ import java.util.Map.Entry;
* @author * @author
*/ */
public class HttpKit { public class HttpKit {
/**
* 问号
*/
public static final String QUESTION_MARK = "?";
private static final String DEFAULT_CHARSET = "UTF-8"; private static final String DEFAULT_CHARSET = "UTF-8";
private static final Logger LOGGER = Logger.getLogger(HttpKit.class); private static final Logger LOGGER = Logger.getLogger(HttpKit.class);
@ -158,8 +162,8 @@ public class HttpKit {
return url; return url;
} }
StringBuilder sb = new StringBuilder(url); StringBuilder sb = new StringBuilder(url);
if (url.indexOf("?") == -1) { if (url.indexOf(QUESTION_MARK) == -1) {
sb.append("?"); sb.append(QUESTION_MARK);
} else { } else {
sb.append("&"); sb.append("&");
} }

@ -10,6 +10,11 @@ import java.util.Set;
*/ */
public abstract class AbstractDbBuiler { public abstract class AbstractDbBuiler {
/**
* 括号
*/
public static final String BRACKETS = ")";
/** /**
* 自动同步表结构 * 自动同步表结构
* @param classSet * @param classSet
@ -47,7 +52,7 @@ public abstract class AbstractDbBuiler {
//SQL 转成大写适 //SQL 转成大写适
String upperCaseSql = sql.toUpperCase(); String upperCaseSql = sql.toUpperCase();
//统计SQL排除排序SQL代码 //统计SQL排除排序SQL代码
if (sql.lastIndexOf(SqlConstant.ORDER_SQL)>sql.lastIndexOf(")")){ if (sql.lastIndexOf(SqlConstant.ORDER_SQL)>sql.lastIndexOf(BRACKETS)){
sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length(),upperCaseSql.lastIndexOf(SqlConstant.ORDER_SQL))); sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length(),upperCaseSql.lastIndexOf(SqlConstant.ORDER_SQL)));
}else{ }else{
sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length())); sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length()));

Loading…
Cancel
Save