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

时间:2016-02-26 10:50:01

标签: spring spring-mvc jersey jersey-2.0 request-mapping

我正在将所有Spring Services转换为Jersey,当我遇到一个关于如何将Spring的RequestParam的 params 功能转换为Jersey的问题时?

@RequestMapping(值=" /收入", 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"在泽西? Jersey是否支持基于Param的过滤请求?

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

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

1 个答案:

答案 0 :(得分:0)

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

我通过创建一个接受呼叫的父服务并基于参数将呼叫重定向到相应的服务来解决这个问题。

@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() {}

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