我正在尝试制作Spring Rest程序,但是当我尝试调用post方法创建学生记录时遇到以下错误
@RestController
@RequestMapping(value="/rest/api/v1")
public class StudentController {
@Autowired
StudentServiceImpl studentService;
StudentRepository stdrepo;
@GetMapping(value="/", produces="application/json")
public ResponseEntity<Response> getWelcomeMessage(){
Response response = new Response();
response.setMessage("Welcome To Student Manageent Page");
response.setStatus(Boolean.TRUE);
response.setCode(HttpStatus.OK.value());
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}
@PostMapping(value = "/create",consumes="application/json", produces="application/json")
public ResponseEntity<StudentResponseModel> createStudent(@RequestBody StudentModel student){
StudentResponseModel response = studentService.createStudent(student);
response.setCode(HttpStatus.OK.value());
response.setStatus(Boolean.TRUE);
response.setMessage("Student Profile Created Successfully");
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}
我的存储库类代码是这个
@Repository
public interface StudentRepository extends CrudRepository<Student, Integer>{
List<Student> findByName(@Param("name") String name);
//@Query("SELECT s FROM STUDENT s where s.id = :id")
Student findById(@Param("id") int id);
//@Query("SELECT s.Name FROM STUDENT s where s.section = :section")
List<Student> findBySection(@Param("section") String section);
}