Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复@DeleteMapping的BootstrapModal_Java_Spring_Bootstrap 4 - Fatal编程技术网

Java 如何修复@DeleteMapping的BootstrapModal

Java 如何修复@DeleteMapping的BootstrapModal,java,spring,bootstrap-4,Java,Spring,Bootstrap 4,我在控制器中有下一个方法: @GetMapping("/delete") public String deleteUser(int id) { groupService.deleteById(id); return REDIRECT_PAGE; } 它与下一个UI完美配合: <a th:href="@{/groups/delete/(id=${group.id})}" class="btn

我在控制器中有下一个方法:

@GetMapping("/delete")
    public String deleteUser(int id) {
        groupService.deleteById(id);
        return REDIRECT_PAGE;
    }
它与下一个UI完美配合:

<a th:href="@{/groups/delete/(id=${group.id})}" class="btn btn-danger">Delete</a>
但现在我想在控制器中用@DeleteMapping更改@GetMapping(开始学习Spring安全性),以及我所拥有的-

Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
我需要修什么? 提前谢谢

Upd: 那么,如果不可能的话,如何添加到SpringSecurity配置规则以允许仅为“admin”删除? 我尝试了下一个,但不起作用-“用户”可以删除条目:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
        .authorizeRequests()
        .antMatchers(HttpMethod.GET, "/**").hasAnyRole(Role.ADMIN.name(), Role.USER.name())
        .antMatchers(HttpMethod.GET, "/groups/delete/*").hasRole(Role.ADMIN.name())
        .antMatchers(HttpMethod.GET, "/groups/delete/").hasRole(Role.ADMIN.name())
        .antMatchers(HttpMethod.GET, "/groups/delete").hasRole(Role.ADMIN.name())
                .antMatchers(HttpMethod.POST, "/**").hasRole(Role.ADMIN.name())
                .antMatchers(HttpMethod.PUT, "/**").hasRole(Role.ADMIN.name())
                .antMatchers(HttpMethod.DELETE, "/**").hasRole(Role.ADMIN.name())
                .anyRequest().authenticated().and()
                .httpBasic();
    }

看起来您仍然在发送GET请求而不是DELETE,但是没有更多的GET端点,这会导致错误。

看起来您仍然在发送GET请求而不是DELETE,但是没有更多的GET端点,这会导致错误。

如果要使用
@DeleteMapping
注释,我认为您需要使用ajax发出请求,否则它应该保持
@GetMapping

如果要使用
@requeustparam

$.ajax({
    type : "DELETE",
    url : "/groups/delete",
    data: {"id": id},
    contentType: "application/json",
    dataType : 'json',
    success: function (result) {       
        console.log(result);                
    },
    error: function (e) {
        console.log(e);
    }
});
浏览器仅支持GET和POST as http请求方法


另外,如果您想使用
@PostMapping

解决它,如果您想使用
@DeleteMapping
注释,我认为您需要使用ajax发出请求,否则它应该保持
@GetMapping

如果要使用
@requeustparam

$.ajax({
    type : "DELETE",
    url : "/groups/delete",
    data: {"id": id},
    contentType: "application/json",
    dataType : 'json',
    success: function (result) {       
        console.log(result);                
    },
    error: function (e) {
        console.log(e);
    }
});
浏览器仅支持GET和POST as http请求方法


另外,如果你想用
@PostMapping

解决这个问题,你看过这个答案了吗?如果您将请求映射更改为
@DeleteMapping
,那么链接即
@clD很好,似乎我需要为所有路径配置Spring安全性,而不仅仅是通过HttpMethod。*您看过这个答案了吗?如果您将请求映射更改为
@DeleteMapping
,那么链接即
@clD很好,似乎我需要为所有路径配置Spring安全性,而不仅仅是通过HttpMethod。*我用这个替换我以前的js代码,并在控制器中设置@DeleteMapping,但如果我在模式窗口上按确认,我有一条关于“GET”的消息,我又添加了一个修复程序,可能是关于这个。我用这个替换了我以前的js代码,并在控制器中设置@DeleteMapping,但如果我在模式窗口上按Confirm,我还有一条关于“GET”的消息,我又添加了一个修复程序,可能是关于这个。
$.ajax({
    type : "DELETE",
    url : "/groups/delete",
    data: {"id": id},
    contentType: "application/json",
    dataType : 'json',
    success: function (result) {       
        console.log(result);                
    },
    error: function (e) {
        console.log(e);
    }
});