我有一个扩展的通用Spring Data存储库接口QuerydslBinderCustomizer
,允许我自定义查询执行.我正在尝试将内置的基本相等性测试扩展到默认存储库实现中,以便我可以使用Spring Data REST执行其他查询操作.例如:
GET /api/persons?name=Joe%20Smith // This works by default GET /api/persons?nameEndsWith=Smith // This requires custom parameter binding.
我遇到的问题是我创建的实体路径的每个别名似乎都覆盖了前面的别名绑定.
@NoRepositoryBean public interface BaseRepositoryextends PagingAndSortingRepository , QueryDslPredicateExecutor , QuerydslBinderCustomizer { @Override @SuppressWarnings("unchecked") default void customize(QuerydslBindings bindings, EntityPath entityPath){ Class model = entityPath.getType(); Path root = entityPath.getRoot(); for (Field field: model.getDeclaredFields()){ if (field.isSynthetic()) continue; Class> fieldType = field.getType(); if (fieldType.isAssignableFrom(String.class)){ // This binding works by itself, but not after the next one is added bindings.bind(Expressions.stringPath(root, field.getName())) .as(field.getName() + "EndsWith") .first((path, value) -> { return path.endsWith(value); }); // This binding overrides the previous one bindings.bind(Expressions.stringPath(root, field.getName())) .as(field.getName() + "StartsWith") .first((path, value) -> { return path.startsWith(value); }); } } } }
是否可以为同一个字段创建多个别名?这可以通用的方式完成吗?