当前位置:网站首页>"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 .
边栏推荐
- Worthington - chemical properties and related studies of Worthington trypsin
- Sword finger offer 41. median in data flow
- SQL实现将多行记录合并成一行
- Is the declarative code of compose so concise?
- Build SSM project with JSP as view parser
- Exchange 2013 SSL certificate installation document
- Type 1-5 components
- #{}和${}的区别
- Leetcode59. 螺旋矩阵 II
- Okaleido ecological core equity Oka, all in fusion mining mode
猜你喜欢

DevOps在物联网解决方案中的应用

DoIP测试开发实践

Use pytoch to quickly train the network model

Real time data warehouse: meituan's implementation of real-time data warehouse construction based on Flink

Worthington - chemical properties and related studies of Worthington trypsin
![[MySQL series] MySQL database foundation](/img/50/cc75b2cdf6e52714c1d492fa1ae2c4.png)
[MySQL series] MySQL database foundation

Classification and determination method of Worthington stemxyme

SQL implementation merges multiple rows of records into one row

【TA-霜狼_may-《百人计划》】美术2.2 模型基础

Powercli batch add esxi to vCenter
随机推荐
1-7 solve the problem of this pointing of methods in classes
[TA frost wolf \u may - "hundred people plan"] Figure 3.6 texture compression - inclusion slimming
Explanation of history and chemical properties of Worthington ribonuclease B
【TA-霜狼_may-《百人计划》】图形3.6 纹理压缩——包体瘦身术
ISO 13400(DoIP)标准解读
Web系统常见安全漏洞介绍及解决方案-CSRF攻击
Connection pool - return connection details (Part 2)
EN 12101-8:2011 smoke dampers for smoke and heat control systems - CE certification
Review of categories 1-4
Principle of meter skipping
【MySQL 8】Generated Invisible Primary Keys(GIPK)
Websocket heartbeat mechanism (keep alive mechanism)
laptop外接显示器
Es6操作教程
VMware VCSA 7.0 Install
#{}和${}的区别
Summary of wrong questions of software designers
EN 1873屋面用装配附件.塑料单个屋面灯—CE认证
Exchange 2013 SSL certificate installation document
1-4 类的复习