过滤泽西岛的资源,类似于 Spring @RequestMapping "Params"属性



我正在将所有的 Spring 服务转换为泽西岛,当我遇到一个关于如何将 Spring 的 RequestParam 参数功能转换为泽西岛的问题时?

@RequestMapping(value = "/earnings", params = "type=csv"

春天:

@RequestMapping(value = "/earnings", params = "type=csv")
public void earningsCSV() {}
@RequestMapping(value = "/earnings", params = "type=excel")
public void earningsExcel() {}
@RequestMapping("/earnings")
public void earningsSimple() {}

泽西:

@Path("/earnings") 
public void earningsCSV() {}
@Path("/earnings")
public void earningsExcel() {}
@RequestMapping("/earnings")
public void earningsSimple() {}

如何在泽西岛指定类型"csv/excel"?泽西岛甚至支持基于 Param 的过滤请求吗?

如果没有,有什么方法可以做到这一点吗?我正在考虑一个过滤器来处理它们并重定向请求,但我有近 70+ 个服务需要以这种方式解决。所以我最终必须为所有这些编写一个过滤器。此外,这听起来不像是一种干净的方法。

任何建议将不胜感激。提前谢谢。

泽西岛没有配置来定义这一点,就像它在春天所做的那样。

我通过创建一个父服务来解决这个问题,该服务接受调用并根据参数将调用重定向到相应的服务。

@Path("/earnings")
public void earningsParent(@QueryParam("type") final String type) {
    if("csv".equals(type)) 
         return earningsCSV();
    else if("excel".equals(type)) 
         return earningsExcel();
    else 
         return earningsSimple();
}
public void earningsCSV() {}
public void earningsExcel() {}
public void earningsSimple() {}

我觉得这种方法比过滤器更好,因为如果需要扩展过滤器,它不需要开发人员将来更改过滤器。

最新更新