当前位置:网站首页>"Method not allowed", 405 problem analysis and solution
"Method not allowed", 405 problem analysis and solution
2022-07-29 00:12:00 【jiey0407】
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
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/deleteid=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 .
边栏推荐
- Eight performance analysis indicators of effective supply chain management (Part 1)
- Linux之yum安装MySQL
- VirtualLab基础实验教程-8.傅里叶变换(1)
- 实时数仓:美团点评Flink的实时数仓应用分享
- Plato farm is expected to further expand its ecosystem through elephant swap
- Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)
- mysql索引失效的常见9种原因详解
- 【C】 Replace spaces and realize binary parity bit exchange of integers by macros
- Yolov5 learning notes (I) -- principle overview
- Have passed hcip and joined the company of your choice, and share the learning experience and experience of Huawei certification
猜你喜欢

DoIP测试开发实践

EN 1935 building hardware. Single axis hinge - CE certification

mysql索引失效的常见9种原因详解

Have passed hcip and joined the company of your choice, and share the learning experience and experience of Huawei certification

【C】替换空格,宏实现整数的二进制奇偶位交换

MySQL安装配置教程(超级详细、保姆级)

Compose 的声明式代码如此简洁?

有效供应链管理的八大绩效分析指标(上)

Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click

Real time data warehouse: Netease strictly selects the practice of real-time data warehouse based on Flink
随机推荐
【TA-霜狼_may-《百人计划》】美术2.2 模型基础
Leetcode 763. partition labels divide alphabetic intervals (medium)
curl (7) Failed connect to localhost8080; Connection refused
Pycharm configuring the running environment
【小程序项目开发 -- 京东商城】uni-app 商品分类页面(上)
SQL实现将多行记录合并成一行
[TA frost wolf _may- "hundred people plan"] art 2.2 model basis
[TA frost wolf \u may - "hundred people plan"] Figure 3.6 texture compression - inclusion slimming
How can Plato obtain premium income through elephant swap in a bear market?
Dual for loop optimization
Oracle创建表空间和用户
Do you know any formal part-time platforms?
[microservice] Nacos cluster building and loading file configuration
Three years after graduation, write to you and me who may be confused [turn]
Oracle create tablespaces and users
Review of categories 1-4
laptop外接显示器
Sword finger offer 55 - I. depth of binary tree
GhostNets on Heterogeneous Devices via Cheap Operations
PowerCL 批量创建及管理虚拟交换机