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);
}
即使禁用第二種方法也不行。
我從你的例子複製了標題。嘗試擺脫模型,並看看產品=應該可用 – jstuartmilne
對不起:在我們的Spring 3產生=不可用。對不起,這令人困惑。 –
愚蠢的問題,但你是如何設置你的豆?你可以發佈你的applicationContext.xml嗎?你是使用 ? –
jstuartmilne