【问题标题】:Request method 'DELETE' not supported angularsjs springboot请求方法'DELETE'不支持angularjs spring boot
【发布时间】:2015-06-24 04:07:07
【问题描述】:

你好,我正在使用 spring boot ,restful web service 和 angularjs,

这是我的休息控制器

@RestController
@RequestMapping("/structure")
public class StructureNotificationRestContolleur {

 @Autowired
 StructureNotificationService StructureNotif;
 @Autowired
 ChampService champService;

 @RequestMapping(value = "/deleteChamp/{ch}", method=RequestMethod.DELETE )
    public @ResponseBody void DeleteChamp(@PathVariable (value="ch") int ch) 
    {
     champService.DeleteChamp(ch);
    }

有删除按钮:

$scope.deleteST= function(ids)
            {
                 $http.delete('/structure/deleteChamp/'+ids).
                 success(function(data) {
                     alert(ids);

                 });

            }

但有错误: os.web.servlet.PageNotFound:不支持请求方法“DELETE”

???

【问题讨论】:

  • 什么是'/structure/deleteChamp/'+ids?它存在吗?
  • /structure/deleteChamp/ 这是要删除的其余方法的路径,“ids”是要删除的元素的id ???
  • 我认为 spring boot 不知道方法 'DELETE' ???不支持请求方法“DELETE”
  • 您可以尝试仅测试服务吗?我认为当你从 angularjs 调用服务时,你并没有告诉它是哪种方法。
  • 当我从我的 RestControlleur 类中删除 method=RequestMethod.DELETE 并在酒吧地址localhost:8080/structure/deleteStruct/AE 中写入这一行时,它起作用了!!!!!!!!!!!!!!! !! id 为“AE”的字段正在删除

标签: javascript angularjs spring-boot spring-data-rest


【解决方案1】:
$scope.deleteST= function(ids)
        {
             $http.delete('/structure/deleteChamp/', ids).
             success(function(data) {
                 alert(ids);

             });

        }

Edit*** 澄清:+ 参数作为加法表示你最终会得到一个字符串作为操作的结果,而“,”参数意味着你最终会得到一个字符串 URL 加上 javascript/您需要的 Json 对象。

尝试使用“,”而不是“+”

【讨论】:

  • 虽然这段代码可能会回答这个问题,但最好在不介绍其他代码的情况下解释它是如何解决问题的,以及为什么要使用它。从长远来看,纯代码的答案没有用处。
猜你喜欢
  • 2019-11-07
  • 1970-01-01
  • 2017-10-28
  • 2018-06-03
  • 2014-05-15
  • 2020-03-31
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多