Commit edc89a28 authored by yanzg's avatar yanzg

接口文档的支持

parent 3eaf2dd2
package com.yanzuoguang.util.helper;
import java.util.*;
/**
* 字符串帮主类
*
* @author 颜佐光
*/
public class ArrayHelper {
/**
* 合并为数组列表
*
* @param from 参数列表
* @param froms 参数列表
* @return 第一个非空字符串
*/
public static <T extends Object> List<T> megerNotEmpty(T from, List<T> froms) {
List<T> tos = new ArrayList<>();
if (!StringHelper.isEmpty(from)) {
tos.add(from);
}
if (froms != null) {
for (T item : froms) {
if (!StringHelper.isEmpty(item)) {
tos.add(item);
}
}
}
return tos;
}
/**
* 判断对象是否是数组或者List
*
* @param val
* @return
*/
public static boolean isArrayOrList(Object val) {
boolean isArray = val != null && (val instanceof List || val.getClass().isArray());
return isArray;
}
/**
* 获取对象为对象列表
*
* @param val 需要获取的对象,可以为List或者Array或者其他对象.
* @return
*/
public static List getList(Object val) {
boolean isArray = isArrayOrList(val);
List list;
// 判断处理
if (val instanceof List) {
list = (List) val;
} else if (isArray) {
Object[] arr = (Object[]) val;
list = Arrays.asList(arr);
} else {
list = new ArrayList();
list.add(val);
}
return list;
}
}
......@@ -8,10 +8,7 @@ import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......
......@@ -7,6 +7,7 @@ import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.MapRow;
import com.yanzuoguang.util.vo.PageSizeData;
......@@ -526,7 +527,7 @@ public abstract class BaseDaoSql {
// 根据输入字段从参数中取值
Object val = ObjectHelper.get(model, field);
// 判断是否为数组
boolean isArray = val != null && (val instanceof List || val.getClass().isArray());
boolean isArray = ArrayHelper.isArrayOrList(val);
if (isArray) {
sql = getListSql(paras, sql, name, val);
} else {
......@@ -547,7 +548,9 @@ public abstract class BaseDaoSql {
*/
private Object getParaValue(Object val) {
if (val instanceof Boolean) {
val = (Boolean)val ? 1 : 0;
val = (Boolean) val ? 1 : 0;
} else if (val instanceof Double || val instanceof Float) {
val = StringHelper.toDouble(val);
}
val = StringHelper.toString(val);
return val;
......@@ -563,15 +566,7 @@ public abstract class BaseDaoSql {
* @return 获取包含列表的SQL语句的值
*/
private String getListSql(List<Object> paras, String sql, String name, Object val) {
List list;
// 判断处理
if (val instanceof List) {
list = (List) val;
} else {
Object[] arr = (Object[]) val;
list = Arrays.asList(arr);
}
List list = ArrayHelper.getList(val);
int length = list.size();
// 进行循环
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment