当前位置:网站首页>"Method not allowed", 405 problem analysis and solution
"Method not allowed", 405 problem analysis and solution
2022-06-26 00:32:00 【Hoh Xil's flight】
First , Be clear 405 The problem is the browser side ( Or client ) The request method is inconsistent with the processing method of the server for processing the request of this path .
background :SpringBoot2.70 Integrate JPA, Addition, deletion, modification and query of test sheet table
The phenomenon : In use postman test delete Method encountered 
Of
chart 1: postman Test screenshot 
chart 2: Back end code block
package com.xxxx.salesforecast.Controller;
import com.xxxx.salesforecast.pojo.User;
import com.xxxx.salesforecast.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** * User external interface * * @author : liuke * @date : 2022-06-22 14:20 **/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserRepository userRepository;
/** * Insert * * @param user * @return */
@PostMapping
public String addUser(@RequestBody User user) {
userRepository.save(user);
return "success";
}
/** * Query all * * @return */
@GetMapping("")
public List<User> getAllUser() {
List<User> userList = userRepository.findAll();
return userList;
}
/** * according to id Delete * @param id * @return */
@DeleteMapping("/{id}")
public String deleteUserById(@PathVariable Integer id){
userRepository.deleteById(id.intValue());
return "success";
}
}
Figure 3 : Console error 
Troubleshooting process :
First step : Check your code roughly , I feel OK , Start Baidu
The second step : The first plan Baidu got , Unresolved
application.yml Add spring mvc: hiddenmethod: filter: enabled: true
This starts HiddenHttpMethodFilter filter , To support the browser can send DELETE PUT request . And I don't send requests with my browser , It's about using postman, So useless is also normal .
The third step : Try to @DeleteMapping Change to @RequestMapping, Unresolved
Step four : Try to get rid of @PathVariable annotation , Unresolved
Step five : The thought of , I use it restful Interface , The paths for adding, deleting, and modifying queries are the same , adopt @PostMapping、@PutMapping、@DeleteMapping、@GeMapping To distinguish behaviors .
So the path of the method is modified , Not yet. . But it is not reported at this time 405 了 , Start reporting 404 了 .
404, As we all know, there must be no matching path .
Then I finally found the problem , Path below
http://localhost:6060/user/delete?id=1
there id It is in the form of parameter transmission
and @DeleteMapping(“/delete/{id}”) It means id When the path
So the path is changed to
reflection : Why did you report it before 405 The error? ?
Because it matches the query interface , This interface is @GetMapping, So and @DeleteMapping Don't agree with each other , Just report it 405 error .
And this interface does not need to pass parameters , If the parameter is passed, no error will be reported , such as , We visit http://baidu.com and http://baidu.com/?sbbaidu=1 It's the same

summary : The problem is that I put @DeleteMapping(“/{id}”) Of id When the path and path parameters are confused .
边栏推荐
- Mysql5.7.31自定义安装详细说明
- 【超能云终端创领先机】如何在48小时内交付一座方舱医院?
- About Simple Data Visualization
- SMT行业AOI,X-RAY,ICT分别是什么?作用是?
- After being trapped by the sequelae of the new crown for 15 months, Stanford Xueba was forced to miss the graduation ceremony. Now he still needs to stay in bed for 16 hours every day: I should have e
- 解决线程并发安全问题
- 性能领跑云原生数据库市场!英特尔携腾讯共建云上技术生态
- 在同一台机器上部署OGG并测试
- farsync 简易测试
- Ora-01153: incompatible media recovery activated
猜你喜欢

正则表达式介绍及一些语法

DNS review

MySQL master-slave replication

anchor free dection简介

性能领跑云原生数据库市场!英特尔携腾讯共建云上技术生态

The development context of Ba Kong Yuan universe industry

Atlas200dk刷机

leetcode.14 --- 最长公共前缀

【TSP问题】基于Hopfield神经网络求解旅行商问题附Matlab代码

Research and development practice of Kwai real-time data warehouse support system
随机推荐
EBS R12.2.0升级到R12.2.6
Redux workflow + complete code of small examples
删库跑路、“投毒”、改协议,开源有哪几大红线千万不能踩?
Camkiia et gcamp6f sont - ils les mêmes?
【超能云终端创领先机】如何在48小时内交付一座方舱医院?
redux工作流程讲解+小例子
leetcode. 14 --- longest public prefix
"Seamless" deployment of paddlenlp model based on openvinotm development kit
快手实时数仓保障体系研发实践
linux安装redis
Oracle RAC cluster failed to start
Should group by be used whenever aggregate functions are used in SQL?
14.1.1 promethues monitoring, four data types metrics, pushgateway
SMT葡萄球现象解决办法
Logstash discards log data that does not match the file name exactly
redux工作流程+小例子的完整代码
Redis jump table
CaMKIIa和GCaMP6f是一样的嘛?
Summary of common terms and knowledge in SMT chip processing industry
Explain from a process perspective what happens to the browser after entering a URL?