Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dbproject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
- import org.springframework.ui.Model;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import javax.validation.Valid;
- @org.springframework.stereotype.Controller
- @EnableAutoConfiguration
- public class Controller {
- @Autowired
- StudentRepository studentRepository;
- @Autowired
- StudentsService studentsDB;
- @RequestMapping(name="/", method = RequestMethod.GET)
- public String main(Model model) {
- model.addAttribute("students", studentsDB.getStudents());
- return "students";
- }
- @RequestMapping(name="/addStudent", method = RequestMethod.GET)
- public String addNewStudent(Model model) {
- model.addAttribute("newStudent",new Student());
- return "addStudent";
- }
- @RequestMapping(name="/addStudent/send", method = RequestMethod.POST)
- public String addNewStudent2(@Valid Student newStudent, BindingResult bindingResult, Model model) {
- if (bindingResult.hasErrors()) {
- return "addStudent";
- }
- studentsDB.addStudent(newStudent);
- return "redirect:/";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement