我在 REST,Spring MVC 中有以下代码。此代码应该返回一个名为 ResponseText 的 JSON 类型数据结构:
@RequestMapping(value="/movieTheater", headers = {"ACCEPT=*/*"}, method=RequestMethod.GET)
public @ResponseBody ResponseText getCustomerInput(@RequestParam("name") String name, @RequestParam("price") Double price) {
Transaction transaction = new Transaction();
ResponseText result = new ResponseText();
transaction.setMovieName(name);
transaction.setTicketPrice(price);
transaction.setDatetime(new Date());
if(transactionService.addTransaction(transaction))
result.setMessage(ResponseStatus.SUCCESS.getStatus());
else
result.setMessage(ResponseStatus.FAILED.getStatus());
return result;
}
但是当我通过浏览器中的以下 URL 执行此代码时,我收到以下错误:
网址:
http://localhost:8080/SpringMVCMerchant/movieTheater.htm?name=Smurfs&price=300.00
错误:
HTTP Status 406 -
type Status report
message
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
我无法确定我在这里做错了什么。我在网上查找解释这个错误,但仍然不知道我错过了什么。我已经给出了 ACCEPT=" / ",应该涵盖各种响应,对吧?请帮忙!提前致谢!
** 当我添加标题时
headers={"Accept: application/json, text/javascript"}
而不是上面那个,我得到了以下错误:
HTTP Status 405 - Request method 'GET' not supported