"Method Not Allowed"405问题分析以及解决方法
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;
/**
* 用户外部接口
*
* @author : liuke
* @date : 2022-06-22 14:20
**/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserRepository userRepository;
/**
* 插入
*
* @param user
* @return
*/
@PostMapping
public String addUser(@RequestBody User user) {
userRepository.save(user);
return "success";
}
/**
* 查询全部
*
* @return
*/
@GetMapping("")
public List
List
return userList;
}
/**
* 根据 id 删除
* @param id
* @return
*/
@DeleteMapping("/{id}")
public String deleteUserById(@PathVariable Integer id){
userRepository.deleteById(id.intValue());
return "success";
}
}