使用Spring和Specification-arg-resolver实现查找全部

Pet*_*zov 6 java spring jpa-2.0 spring-data-jpa spring-boot

我想用Specification-arg-resolver和Spring实现Angular的所有功能。

我正在尝试发送此网址:

[HPM] GET /api/be/find?name=tes&login=tes&allowed_ip_address=tes&page=0&size=10
Run Code Online (Sandbox Code Playgroud)

通过spec -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)
Run Code Online (Sandbox Code Playgroud)

当我送参数有关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 ?
Run Code Online (Sandbox Code Playgroud)

Gna*_*yam 0

您可以在 HQL 查询中传递名称、登录名和 ip_address,而不是使用规范类。

public Page<BeDTO> getAllBySpecification(String name,String login,String ip_address,
                Pageable pageable
            ) {        
                return merchantService.getAllBySpecification(name,login,ip_address pageable);
            }

select * from Merchants as merchants where merchants.name like %:name%  and merchants.login like %:login% and merchants.allowed_ip_address like %:allowed_ip_address%
Run Code Online (Sandbox Code Playgroud)