基於上面的代碼,是的,它會奏效。下面是示例代碼片段,你可以看看作爲well.where ConditionType
是枚舉...這樣你也可以準備自己的枚舉(不是強制性的,如果條件也很好)
private Filter buildSimpleQuery(ConditionType ct, String name, Object value) {
name = super.getRealPropertyName(name);
validatePropertyValue(name, value);
Class<?> clazz = getPrimitiveFieldClass(name, value.getClass());
CompareOp compareOp = null;
boolean regexCompRequired = false;
switch (ct) {
case EQUALS:
compareOp = CompareOp.EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case NOT_EQUALS:
compareOp = CompareOp.NOT_EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case GREATER_THAN:
compareOp = CompareOp.GREATER;
break;
case GREATER_OR_EQUALS:
compareOp = CompareOp.GREATER_OR_EQUAL;
break;
case LESS_THAN:
compareOp = CompareOp.LESS;
break;
case LESS_OR_EQUALS:
compareOp = CompareOp.LESS_OR_EQUAL;
break;
default:
break;
}
String qualifier = name;
String theFamily = family != null ? family : familyMap.get(qualifier);
ByteArrayComparable byteArrayComparable = regexCompRequired
? new RegexStringComparator(value.toString().replace("*", "."))
: new BinaryComparator(value.toString().getBytes(StandardCharsets.UTF_8));
Filter query = new SingleColumnValueFilter(theFamily.getBytes(StandardCharsets.UTF_8),
qualifier.getBytes(StandardCharsets.UTF_8),
compareOp,
byteArrayComparable);
return query;
}
它的工作原理。謝謝:) –
因爲它的工作原理,你很好,請標記爲「所有者接受」謝謝 –