【问题标题】:Angularjs , Spring Boot PUT not supported with spring securitySpring Security不支持Angularjs,Spring Boot PUT
【发布时间】:2015-10-06 06:48:18
【问题描述】:

角度控制器功能

$scope.updatePatient = function() {
            var patient = new patientUpdateService({id:"15", name:"m",lastname:"s"});
            patient.$update();
}

角度服务

.factory("patientUpdateService", function ($resource) {
    return $resource("/updatepatient", {id: "@id"}, {
        update: {
            method: 'PUT'
        }
    });
})

Spring 启动控制器

    @RequestMapping(value="/updatepatient/{id}", method=RequestMethod.PUT)
      @ResponseBody
      public Patients update(@PathVariable("id") int id, @RequestBody @Valid Patients patient) {
       return patientrep.save(patient);

}

我正在使用 angularjs 和 springboot 制作简单的 crud 操作应用程序,但出现以下错误:

在 Angular 中:PUT http://localhost:8080/updatepatient?id=15 405(不允许的方法)

在 Tomcat 中:o.s.web.servlet.PageNotFound:不支持请求方法“PUT”

我正在使用 CRUDRepository ; Get、POST、DELETE 工作正常。

【问题讨论】:

  • 阅读错误信息。 Angular 将请求发送到updatepatient?id=15。但是你的 spring 控制器映射到/updatepatient/15
  • 所以在 spring 控制器中,我应该放什么请求映射,我尝试了 value="/updatepatient?id={id}" ,但它不起作用
  • 非常感谢它现在工作,在角度控制器中我更改为 /updatepatient/:id"

标签: angularjs spring-boot


【解决方案1】:

Angular 正在发送查询参数而不是路径变量,要映射查询参数,您必须使用 @RequestParam 注释,这是一个示例

@RequestMapping(value="/group/", method=RequestMethod.GET)
    @ResponseBody
    public MetaListDto<UserDto> findUsersForGroup(@RequestParam(value="id", required=false)  Long groupId,@RequestParam(value="offset", required=false)  Integer offset,@RequestParam(value="limit", required=false)  Integer limit)  {

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 1970-01-01
    • 2014-05-15
    • 2020-05-26
    • 1970-01-01
    • 2017-07-09
    • 2015-06-24
    • 2021-08-09
    • 2015-03-03
    相关资源
    最近更新 更多