我做了这个休息,首先看一下所有必须正常工作,但我抓住了405。
HTTP状态405 - 请求方法' GET'不支持
应用程序上下文
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager){
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);
List<ViewResolver> resolvers = new ArrayList<ViewResolver>();
resolvers.add(getViewResolver());
resolvers.add(jsonViewResolver());
resolver.setViewResolvers(resolvers);
return resolver;
}
@Bean
public ViewResolver jsonViewResolver(){
return new JsonViewResolver();
}
控制器
@RequestMapping(value="/rest/create/{login}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public @ResponseBody User updateUser(@RequestBody User user, @PathVariable String login){
dao.saveUser(user);
return user;
}
答案 0 :(得分:2)
将method = RequestMethod.PUT
更改为method = RequestMethod.GET
,或在现有映射上使用PUT请求。
如果您不想使用插件,可以使用jQuery创建PUT请求
$.ajax({
url: someUrl,
data: someData,
type: 'PUT',
success: function(result) {
// Do something with the result
}
});
答案 1 :(得分:0)
将RequestMethod.PUT
更改为RequestMethod.GET
@RequestMapping(value="/rest/create/{login}", method = RequestMethod.GET)
如果您想使用put方法,请相应地修改HTML表单标签和控制器
示例 HTML表单
<form:form id="mainForm" name="mainForm" method="PUT" action="Temp.htm" enctype="multipart/form-data" commandName="tempBean">
Spring Controller
@RequestMapping(value="/rest/create/{login}", method = RequestMethod.PUT)