2015-10-09 30 views
0

如何为普通和rest/ajax请求使用相同的url。我有以下代码,我的Ajax调用总是接收普通的html而不是JSON。Restful的重复弹簧控制器方法@RequestMapping

@RequestMapping(value="/customer/{customerID}/site/{siteID}", method=RequestMethod.GET, headers="Accept=application/json") 
public @ResponseBody Site getSiteJson(HttpServletResponse response, Model model, @PathVariable("customerID") String customerID, @PathVariable("siteID") String siteID) throws IOException, InterruptedException 
{ 
    try 
    { 
     return dao.getSite(customerID, siteID); 
    } 
    catch (NuviaError nuviaError) 
    { 
     response.sendError(500, nuviaError.getMessage()); 
     return null; 
    } 
} 

@RequestMapping(value="/customer/{customerID}/site/{siteID}", method=RequestMethod.GET) 
public String getSite(Model model, @PathVariable("customerID") String customerID, @PathVariable("siteID") String siteID) throws IOException, InterruptedException 
{ 
    Site s; 
    try 
    { 
     s = dao.getSite(customerID, siteID); 
    } 
    catch (NuviaError e) 
    { 
     ControllerUtils.addError(model, "Error fetching site details: " + e.getMessage()); 
     return getCustomer(model, customerID); 
    } 
    return showSite(model, customerID, s, "", "PUT", "Save site details", true); 
} 

即使禁用第二种方法也不行。

回答

0

在我看来,你是不是设置内容类型的响应

​​

这里反正reciving模型模式是怎么样的混乱,你甚至不使用它,所以我会摆脱这

+0

我从你的例子复制了标题。尝试摆脱模型,并看看产品=应该可用 – jstuartmilne

+0

对不起:在我们的Spring 3产生=不可用。对不起,这令人困惑。 –

+0

愚蠢的问题,但你是如何设置你的豆?你可以发布你的applicationContext.xml吗?你是使用 ? – jstuartmilne