当前位置:网站首页>"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 .
边栏推荐
猜你喜欢
Law and self-regulation in the meta universe
idea设置mapper映射文件的模板
Cloud rendering and Intel jointly create the "core" era of cloud rendering
删库跑路、“投毒”、改协议,开源有哪几大红线千万不能踩?
每日刷题记录 (四)
机器视觉:照亮“智”造新“视”界
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
CaMKIIa和GCaMP6f是一样的嘛?
小红书微服务框架及治理等云原生业务架构演进案例
基于OpenVINOTM开发套件“无缝”部署PaddleNLP模型
随机推荐
被新冠后遗症困住15个月后,斯坦福学霸被迫缺席毕业典礼,现仍需每天卧床16小时:我本该享受20岁的人生啊...
Oracle RAC cluster failed to start
What are AOI, X-ray and ICT in SMT industry? What does it do?
MySQL master-slave replication
What is micro service
86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
Research and development practice of Kwai real-time data warehouse support system
What do SMT operators do? operating duty?
CaMKIIa和GCaMP6f是一樣的嘛?
Apache基金会正式宣布Apache InLong成为顶级项目
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
How ASA configures port mapping and pat
Farsync simple test
Graduation season | fitting the best self in continuous exploration
安装PSU的时候/usr/bin/ld:warning: -z lazyload ignore
Detailed explanation of redis
[advanced ROS] Lecture 1 Introduction to common APIs
Redux workflow explanation + small examples
Use Coe_ load_ sql_ profile. SQL fixed execution plan
smt贴片加工行业pcba常见测试方法优劣分析比较