java 构建mybatis

master
e 2019-05-20 23:48:54 +08:00
parent ade53a6886
commit 2358d7467f
3 changed files with 128 additions and 5 deletions

View File

@ -0,0 +1,109 @@
package com.zzjee.wmutil.sql;
import org.jeecgframework.core.util.StringUtil;
import java.util.Map;
public class sqlUtils {
public static String getAndLike(String sql, String filedName, Object params) {
if (StringUtil.isNotEmpty(params)) {
sql += " AND " + filedName + " LIKE '%" + params + "%'\n";
return sql;
} else {
return sql;
}
}
public static String getOrLike(String sql, String filedName, Object params) {
if (StringUtil.isNotEmpty(params)) {
sql += " OR " + filedName + " LIKE '%" + params + "%'\n";
return sql;
} else {
return sql;
}
}
public static String getAndEqual(String sql, String filedName, Object params) {
if (StringUtil.isNotEmpty(params)) {
sql += " AND " + filedName + " = '" + params + "'\n";
return sql;
} else {
return sql;
}
}
public static String getOrEqual(String sql, String filedName, Object params) {
if (StringUtil.isNotEmpty(params)) {
sql += " OR " + filedName + " = '" + params + "'\n";
return sql;
} else {
return sql;
}
}
public static String getIn(String sql, String filedName, Object params) {
if (StringUtil.isNotEmpty(params)) {
String tmpParams = params.toString();
if (tmpParams.indexOf("(") == -1) {
tmpParams = "(" + tmpParams;
}
if (tmpParams.indexOf(")") == -1) {
tmpParams = tmpParams + ")";
}
sql += " AND " + filedName + " IN " + tmpParams + "\n";
return sql;
} else {
return sql;
}
}
public static String getBatchAndLike(String sql, String filedName, String key, Map params) {
if (StringUtil.isEmpty(filedName) || StringUtil.isEmpty(key)) {
return sql;
}
String[] names = filedName.split(",");
String[] keys = key.split(",");
int len = names.length;
if (len != keys.length) {
return sql;
}
for (int i = 0; i < len; i++) {
sql = getAndLike(sql, names[i], params.get(keys[i]));
}
return sql;
}
public static String getBatchAndEqual(String sql, String filedName, String key, Map params) {
if (StringUtil.isEmpty(filedName) || StringUtil.isEmpty(key)) {
return sql;
}
String[] names = filedName.split(",");
String[] keys = key.split(",");
int len = names.length;
if (len != keys.length) {
return sql;
}
for (int i = 0; i < len; i++) {
sql = getAndEqual(sql, names[i], params.get(keys[i]));
}
return sql;
}
public static String getBatchIn(String sql, String filedName, String key, Map params) {
if (StringUtil.isEmpty(filedName) || StringUtil.isEmpty(key)) {
return sql;
}
String[] names = filedName.split(",");
String[] keys = key.split(",");
int len = names.length;
if (len != keys.length) {
return sql;
}
for (int i = 0; i < len; i++) {
sql = getIn(sql, names[i], params.get(keys[i]));
}
return sql;
}
}

View File

@ -0,0 +1,19 @@
package com.zzjee.wmutil.sql;
import org.jeecgframework.core.util.StringUtil;
import java.util.Map;
public class wmsqlUtil {
public String queryReSalePlanComDifList(Map params){
String sql ="SELECT RP.*,ROW_NUMBER() over (ORDER BY RP.X13,RP.X2,RP.X3,RP.X4,X12,X15,X17) as ROWNUM \n" +
"\t FROM RE_SALE_PLAN_COMPARE_DIF RP\n" +
"\t WHERE 1=1 \n";
sql = sqlUtils.getBatchAndEqual(sql, "RP.X3,RP.X4,RP.X15,RP.X12,RP.X13",
"area,pq,cn,salefw,years", params);
sql = sqlUtils.getBatchIn(sql, "RP.X3,RP.X4,RP.X12,RP.X15", "areaList,pqList,fws,cnList", params);
sql = sqlUtils.getBatchAndLike(sql,"RP.X15","x15",params);
return sql;
}
}

View File

@ -1,5 +0,0 @@
package com.zzjee.wmutil;
public class wmsqlUtil {
}