如何搜索开头的字段?
How to search field that starts with?
具有过滤功能的 Jhipster 实体 api 例如:
http://localhost:8080/api/general-addresses?postalCode.contains=41
which execute sql: ............. postalCode LIKE '%41%'
http://localhost:8080/api/general-addresses?postalCode.contains=
which execute sql: ............. postalCode LIKE '%%'
Is it possible to make request with sql: LIKE '41%' ?
您可以通过将此值添加为新条件并编写自定义规范来实现。例如添加条件:
private String postalCodeLike;
请注意,我使用的是 String 而不是 StringFilter。
并添加自定义规范:
if (criteria.getPostalCodeLike() != null) {
specification = specification.and((root, criteriaQuery, criteriaBuilder) ->
criteriaBuilder.like(criteriaBuilder.upper(root.join(FirstRelationedEntity_.fieldName, JoinType.INNER).join(SecondRelationedEntity_.fieldName, JoinType.INNER)
.get(Product_.postalCode)), criteria.getPostalCodeLike().toUpperCase() + "%"));
}
具有过滤功能的 Jhipster 实体 api 例如: http://localhost:8080/api/general-addresses?postalCode.contains=41
which execute sql: ............. postalCode LIKE '%41%'
http://localhost:8080/api/general-addresses?postalCode.contains=
which execute sql: ............. postalCode LIKE '%%'
Is it possible to make request with sql: LIKE '41%' ?
您可以通过将此值添加为新条件并编写自定义规范来实现。例如添加条件:
private String postalCodeLike;
请注意,我使用的是 String 而不是 StringFilter。
并添加自定义规范:
if (criteria.getPostalCodeLike() != null) {
specification = specification.and((root, criteriaQuery, criteriaBuilder) ->
criteriaBuilder.like(criteriaBuilder.upper(root.join(FirstRelationedEntity_.fieldName, JoinType.INNER).join(SecondRelationedEntity_.fieldName, JoinType.INNER)
.get(Product_.postalCode)), criteria.getPostalCodeLike().toUpperCase() + "%"));
}