Spring security SpringREST-RequestMethod.PUT不工作
我使用SpringBoot 1.2.6创建了一个SpringRESTAPI。 下面是我的post方法,它是有效的。但是当我创建一个Put方法时,它不起作用。它不获取参数中的数据Spring security SpringREST-RequestMethod.PUT不工作,spring-security,spring-rest,Spring Security,Spring Rest,我使用SpringBoot 1.2.6创建了一个SpringRESTAPI。 下面是我的post方法,它是有效的。但是当我创建一个Put方法时,它不起作用。它不获取参数中的数据 @CrossOrigin @RequestMapping( method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produc
@CrossOrigin
@RequestMapping(
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public String createArticle(String article_name, String article_content, Long image_id, String category,
HttpServletRequest req, Authentication authentication) throws Exception {...}
卖出方法
//编辑文章
@RequestMapping(value = "/{article_id}",
method = RequestMethod.PUT,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public String editArticle(@PathVariable("article_id") Long article_id,
String article_name, String article_content, String category, HttpServletRequest req) throws Exception {...}
我已经设置了调试器,下面是调试快照
通过使用
PUT
方法,它不支持spring引导。是否需要添加任何新配置
Put方法仅在没有任何参数的请求下工作。如果我添加任何查询参数或表单数据,它都不会工作
您将按照下面的代码实现
@RequestMapping(value = "/", method = RequestMethod.PUT)
public @ResponseBody String createArticle(@RequestBody CreateArticle request) {
LOG.info(request.toString());
return "ok";
}
其中,
CreateArticle
是一个请求类,它以json格式传递值,并包括所有参数,如Stringarticle\u name
、Stringarticle\u content
、Longimage\u id
、Stringcategory
、HttpServletRequest-req,身份验证身份验证
请提供有关此API使用的更多信息。您正在使用的请求示例将非常有用。没有参数。这些应该用@RequestParam
注释,旁边应该注册HttpPutFormContentFilter
作为过滤器,以便能够解析请求参数。