0

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

@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”? Jersey 是否支持基于参数的过滤请求?

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

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

4

1 回答 1

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

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

于 2016-03-01T11:08:56.603 回答