【问题标题】:Trying to update db using put mapping尝试使用放置映射更新数据库
【发布时间】:2019-10-01 02:27:49
【问题描述】:

我正在编写一个更新数据库中的字段的休息控制器。但是,当我尝试通过邮递员发送请求以更新字段时,我收到 Request method 'PUT' not supported 错误。请帮助。提前致谢。我正在使用 spring 开发后端。

这是我的仓库:

 @Transactional
    @Modifying
    @Query("UPDATE Report c SET c.name= :nameWHERE c.id = :id")
    void updateName(@Param("id") long id, @Param("name") String name);

我的休息控制器:

@PutMapping("/{id}/{name}")
public void updateName(@PathVariable("id") Long id, @PathVariable("name") String name)
{
   repository.updateName(id,name);

}

邮递员请求

http://localhost:8080/reports?id=1&name=test

【问题讨论】:

    标签: spring rest spring-boot postman


    【解决方案1】:

    您的 url 应该使用路径参数而不是请求参数,并且应该看起来像

    http://localhost:8080/reports/1/test
    

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 2018-05-05
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 2016-01-18
      相关资源
      最近更新 更多