【问题标题】:specification-arg-resolver - URL operators规范参数解析器 - URL 运算符
【发布时间】:2020-12-02 16:14:24
【问题描述】:

查看来自 specification-argument-resolver 的示例代码,

@Controller
  public class SampleController {
    
    @Autowired
    CustomerRepository customerRepository;
    
    @RequestMapping("/find")
    public List<Customer> findByRegistrationDate(
            @And({
                @Spec(path = "name", params = "name", spec = Equal.class),
                @Spec(path = "registrationDate", params = "registrationDate", spec = GreaterThanOrEqual.class)
            }) Specification<Customer> spec) {
        return customerRepository.findAll(spec);
    }
  }
  
  @Entity
  public class Customer {
    String name;
    Date registrationDate;
  }

查看specification-argument-resolver的示例代码,示例请求如下所示:

GET /find?name=John&registrationDate=2020-06-19

有没有办法让查询参数反映实际的运算符。

示例:registrationDate>=2020-06-19 而不仅仅是 =

我正在寻找 RSQL 和规范参数解析器之间的混合体。

【问题讨论】:

  • 让参数名称实际反映所要求的内容不是更容易(也更合乎逻辑)吗?例如。 registeredAfterregisteredAfterInclusive.

标签: spring-boot spring-data-jpa jpa-2.0


【解决方案1】:

你可以只使用这个库:https://github.com/turkraft/spring-filter

它将让您运行搜索查询,例如:

/search?filter= 平均(收视率)> 4.5 brand.name in (“奥迪”、“路虎”)(年> 2018 公里 50000) 和颜色 : '白色' 意外是空的

它也支持日期,并且很好地处理了 n+1 查询问题。

【讨论】:

    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 2014-10-05
    • 2015-12-18
    • 2015-09-06
    • 2010-09-09
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多