Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.school2.controllers;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.example.school2.models.StudentModel;
- import com.example.school2.services.StudentService;
- @RestController
- public class StudentController {
- @Autowired
- private StudentService studentService;
- @CrossOrigin
- @RequestMapping(value = "/students/", method = RequestMethod.POST)
- public void createStudent(@RequestBody StudentModel studentModel){
- System.out.println();
- System.out.println("=======");
- System.out.println(studentModel.getFirstName());
- System.out.println("=======");
- System.out.println();
- studentService.saveStudent(studentModel);
- }
- @CrossOrigin
- @RequestMapping(value = "/students/{id}", method = RequestMethod.GET)
- public ResponseEntity<StudentModel> readStudent(@PathVariable Long id){
- return new ResponseEntity<StudentModel>(studentService.readStudent(id), HttpStatus.OK);
- }
- @CrossOrigin
- @RequestMapping(value = "/students/{id}", method = RequestMethod.PUT)
- public void updateStudent(@PathVariable Long id, @RequestBody StudentModel studentModel){
- studentService.saveStudent(studentModel);
- }
- @CrossOrigin
- @RequestMapping(value = "/students/{id}", method = RequestMethod.DELETE)
- public void deleteStudent(@PathVariable Long id){
- studentService.deleteStudent(id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement