add in primitive
This commit is contained in:
parent
09d1f43da9
commit
afda15a299
@ -2,6 +2,7 @@ package me.chyxion.tigon.mybatis;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import org.springframework.util.Assert;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -137,7 +138,8 @@ public class Search implements Serializable {
|
||||
in(col, (Collection<?>) value);
|
||||
}
|
||||
else if (value.getClass().isArray()) {
|
||||
in(col, (Object[]) value);
|
||||
// may primitive, (Object[]) causes exception
|
||||
in(col, toList(value));
|
||||
}
|
||||
else {
|
||||
criteria.add(new Criterion(CriterionType.EQ, col, value));
|
||||
@ -172,7 +174,9 @@ public class Search implements Serializable {
|
||||
* @return this
|
||||
*/
|
||||
public Search in(String col, Collection<?> values) {
|
||||
criteria.add(new Criterion(CriterionType.IN, col, values));
|
||||
if (values != null && !values.isEmpty()) {
|
||||
criteria.add(new Criterion(CriterionType.IN, col, values));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -521,4 +525,13 @@ public class Search implements Serializable {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Object> toList(Object source) {
|
||||
final int length = Array.getLength(source);
|
||||
final List<Object> list = new ArrayList<>(length);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
list.add(Array.get(source, i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user