Advertisement
TobNil

Untitled

Mar 18th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package com.example.school2.controllers;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.http.HttpStatus;
  5. import org.springframework.http.ResponseEntity;
  6. import org.springframework.web.bind.annotation.CrossOrigin;
  7. import org.springframework.web.bind.annotation.PathVariable;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12.  
  13. import com.example.school2.models.StudentModel;
  14. import com.example.school2.services.StudentService;
  15.  
  16. @RestController
  17. public class StudentController {
  18. @Autowired
  19. private StudentService studentService;
  20.  
  21. @CrossOrigin
  22. @RequestMapping(value = "/students/", method = RequestMethod.POST)
  23. public void createStudent(@RequestBody StudentModel studentModel){
  24. System.out.println();
  25. System.out.println("=======");
  26. System.out.println(studentModel.getFirstName());
  27. System.out.println("=======");
  28. System.out.println();
  29. studentService.saveStudent(studentModel);
  30. }
  31.  
  32. @CrossOrigin
  33. @RequestMapping(value = "/students/{id}", method = RequestMethod.GET)
  34. public ResponseEntity<StudentModel> readStudent(@PathVariable Long id){
  35. return new ResponseEntity<StudentModel>(studentService.readStudent(id), HttpStatus.OK);
  36. }
  37.  
  38. @CrossOrigin
  39. @RequestMapping(value = "/students/{id}", method = RequestMethod.PUT)
  40. public void updateStudent(@PathVariable Long id, @RequestBody StudentModel studentModel){
  41. studentService.saveStudent(studentModel);
  42. }
  43.  
  44. @CrossOrigin
  45. @RequestMapping(value = "/students/{id}", method = RequestMethod.DELETE)
  46. public void deleteStudent(@PathVariable Long id){
  47. studentService.deleteStudent(id);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement