2016-02-26 21 views
0

我正在将所有的Spring服务转换为泽西岛,当我遇到一个关于如何转换RequestParam的params功能的问题时春天到泽西岛?在泽西岛过滤类似于@RequestMapping的资源Spring的“Params”属性

@RequestMapping(值= “/收益”,PARAMS = “类型= 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多种服务需要这样处理。 所以我必须最终为它们写一个过滤器。另外,它听起来不像一个干净的方法。

任何建议,将不胜感激。 在此先感谢。

回答

0

泽西岛没有配置来定义这个,它在春季完成的方式。

我解决了这个问题,通过创建一个父服务来接受呼叫,并根据param重定向到相应的服务。

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

我觉得这种方式比过滤器并不需要开发商去改变未来的过滤器,如果需要延长更好。