【发布时间】:2019-12-02 20:28:36
【问题描述】:
我想用 specification-arg-resolver 和 Spring 实现查找 Angular 的所有功能。
我正在尝试发送这个网址:
[HPM] GET /api/be/find?name=tes&login=tes&allowed_ip_address=tes&page=0&size=10
使用specification-arg-resolver实现
public Page<BeDTO> getAllBySpecification(
@And({
@Spec(path = "name", spec = LikeIgnoreCase.class),
@Spec(path = "login", spec = LikeIgnoreCase.class),
@Spec(path = "allowed_ip_address", spec = LikeIgnoreCase.class)
}) Specification<Be> specification,
Pageable pageable
) {
return merchantService.getAllBySpecification(specification, pageable)
当我将name 的参数发送到login 时,它工作正常。
但是当我发送所有 3 个参数来实现 All 搜索功能时,我什么也得不到。看来我需要一些不同的规格配置。
你知道为什么它不能正常工作吗?
进入日志我得到:
select * from merchants merchants0_ where (upper(merchants0_.name) like ?) and (upper(merchants0_.login) like ?) and (upper(merchants0_.allowed_ip_address) like ?) limit ?
【问题讨论】:
-
您是否尝试通过指定参数和路径来重写规范 @Spec(path="name.merchants", params="name", spec=LikeIgnoreCase.class) ?
-
不,你能给我举个例子吗?
-
1.将您的 BE 实体添加到问题中。 2. 试试这个规范:@And({ @Spec(path = "name", params="name", spec = LikeIgnoreCase.class), @Spec(path = "login", params="login", spec = LikeIgnoreCase .class), @Spec(path = "allowed_ip_address", params="allowed_ip_address", spec = LikeIgnoreCase.class) }
-
你确定数据库中有对应的行吗?代码看起来没问题,生成的查询也没问题。
-
是的,对于单个搜索字符串,它工作正常。
标签: java spring spring-boot spring-data-jpa jpa-2.0