| | |
| | | if (Cools.isEmpty(condition)) { |
| | | return; |
| | | } |
| | | String keyword = String.valueOf(condition).trim(); |
| | | if (keyword.isEmpty()) { |
| | | String keyword = normalizeFilterText(condition); |
| | | if (keyword == null || keyword.isEmpty()) { |
| | | return; |
| | | } |
| | | boolean appended = false; |
| | |
| | | } |
| | | } |
| | | |
| | | protected String normalizeFilterText(Object rawValue) { |
| | | if (rawValue == null) { |
| | | return null; |
| | | } |
| | | String normalized = String.valueOf(rawValue).trim(); |
| | | if (normalized.isEmpty() || "null".equalsIgnoreCase(normalized)) { |
| | | return null; |
| | | } |
| | | return normalized; |
| | | } |
| | | |
| | | protected <T> Object resolveFilterValue(Class<T> cls, String columnName, Object rawValue) { |
| | | String normalized = normalizeFilterText(rawValue); |
| | | if (normalized == null) { |
| | | return null; |
| | | } |
| | | Class<?> fieldType = resolveFieldType(cls, columnName); |
| | | if (fieldType == null) { |
| | | return normalized; |
| | | } |
| | | Object parsedValue = parseExactSearchValue(fieldType, normalized); |
| | | return parsedValue != null ? parsedValue : normalized; |
| | | } |
| | | |
| | | private <T> Class<?> resolveFieldType(Class<T> cls, String columnName) { |
| | | if (cls == null || Cools.isEmpty(columnName)) { |
| | | return null; |
| | | } |
| | | for (Field field : Cools.getAllFields(cls)) { |
| | | if (Modifier.isFinal(field.getModifiers()) |
| | | || Modifier.isStatic(field.getModifiers()) |
| | | || Modifier.isTransient(field.getModifiers())) { |
| | | continue; |
| | | } |
| | | String column = null; |
| | | if (field.isAnnotationPresent(TableField.class)) { |
| | | TableField tableField = field.getAnnotation(TableField.class); |
| | | if (!tableField.exist()) { |
| | | continue; |
| | | } |
| | | column = tableField.value(); |
| | | } |
| | | if (Cools.isEmpty(column)) { |
| | | column = field.getName(); |
| | | } |
| | | if (columnName.equals(column) || columnName.equals(field.getName())) { |
| | | return field.getType(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private boolean supportsLikeSearch(Class<?> fieldType) { |
| | | return CharSequence.class.isAssignableFrom(fieldType) |
| | | || fieldType == Character.class |