为什么我得到状态400,错误的请求在我的POST URL(使用邮差)



我试图跟随youtube上的Spring Boot教程,我在Post上卡住了。我试着搜索修复,但我找不到一个具体的答案,为什么我不能访问post URL?

我尝试了@PostMapping和@RequestMapping(Method = POST)还是一样的结果。

也许我访问我的URL错误?我想张贴在/api/sis/student_reg

需要帮助,谢谢!

@RestController
@RequestMapping(path = "/api/sis")
public class StudentController {
@Autowired
private StudentService studentService;
@GetMapping(path = "/student")
public List<Student> displayStudent(){
return studentService.getStudent();
}
@RequestMapping(method = RequestMethod.POST, value = "/reg_student")
public void registerStudent(@RequestBody Student student){
studentService.addStudent(student);
}
}
@Service
public class StudentService  {
@Autowired
private StudentRepository studentRepository;
private Student students = new Student();
public List<Student> getStudent(){
List<Student> student = new ArrayList<>();
studentRepository.findAll()
.forEach(student::add);
return student;
}
public void addStudent(Student student){
studentRepository.save(student);
}

@Entity
@Table
public class Student {
UUID uuid = UUID.randomUUID();
@Id
@SequenceGenerator(
name = "student_sequence",
sequenceName = "student_sequence",
allocationSize = 1
)
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "student_sequence"
)
private String id;
private String FirstName;
private String LastName;
private String email;

// Method Converting UUID into string
public String genID(){
id = uuid.toString();
return id;
}

//Constructor, getters and setters

编辑:我收到错误400时,使用"Post"而405 &;get &;在帖子的URL。很抱歉造成了误会。

不是url错了。如果是这样的话,你会得到404 Not Found error,而不是400,即错误的请求。这意味着你的要求是不正当的。您是否也可以更新您在postman中使用的整个请求体以及您的学生类的属性。