Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package com.example.dbproject;
  2.  
  3.  
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  6. import org.springframework.ui.Model;
  7. import org.springframework.validation.BindingResult;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10.  
  11. import javax.validation.Valid;
  12.  
  13. @org.springframework.stereotype.Controller
  14. @EnableAutoConfiguration
  15. public class Controller {
  16. @Autowired
  17. StudentRepository studentRepository;
  18.  
  19. @Autowired
  20. StudentsService studentsDB;
  21.  
  22. @RequestMapping(name="/", method = RequestMethod.GET)
  23. public String main(Model model) {
  24. model.addAttribute("students", studentsDB.getStudents());
  25. return "students";
  26. }
  27.  
  28. @RequestMapping(name="/addStudent", method = RequestMethod.GET)
  29. public String addNewStudent(Model model) {
  30. model.addAttribute("newStudent",new Student());
  31. return "addStudent";
  32. }
  33.  
  34. @RequestMapping(name="/addStudent/send", method = RequestMethod.POST)
  35. public String addNewStudent2(@Valid Student newStudent, BindingResult bindingResult, Model model) {
  36. if (bindingResult.hasErrors()) {
  37.  
  38. return "addStudent";
  39. }
  40. studentsDB.addStudent(newStudent);
  41. return "redirect:/";
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement