PackageController;Importmodel. clazzentity;Importmodel. studententity;Importmodel. teacherentity;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.ModelMap;ImportOrg.springframework.web.bind.annotation.ModelAttribute;Importorg.springframework.web.bind.annotation.PathVariable;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod;ImportRepository. Clazzrepository;ImportRepository. Studentsrepository;ImportRepository. Teacherrepository;Importjava.util.List; @Controller Public classMaincontroller {@Autowired studentsrepository studentsrepository; @Autowired teacherrepository teacherrepository; @Autowired clazzrepository clazzrepository; @RequestMapping (Value= "/", method =requestmethod.get) PublicString Index () {return"Index"; } @RequestMapping (Value= "/admin/students", method =requestmethod.get) PublicString getstudents (Modelmap modelmap) {List<StudentEntity> studentlist=Studentsrepository.findall (); Modelmap.addattribute ("Studentlist", studentlist); return"Admin/students"; } @RequestMapping (Value= "/admin/students/add", method =requestmethod.get) PublicString addstudent () {return"Admin/addstudent"; } @RequestMapping (Value= "/admin/students/adds", method =requestmethod.post) PublicString Addstudentpost (@ModelAttribute ("Student") studententity studententity) {Studentsrepository.saveandflush (studententity); return"Redirect:/admin/students"; } @RequestMapping (Value= "/admin/students/show/{sid}", method =requestmethod.get) PublicString showstudent (@PathVariable ("Sid") Integer SID, Modelmap Modelmap) {studententity studententity=Studentsrepository.findone (SID); Modelmap.addattribute ("Student", studententity); return"Admin/studentdetail"; } @RequestMapping (Value= "/admin/students/delete/{sid}", method =requestmethod.get) PublicString deletestudent (@PathVariable ("Sid"Integer SID) {studentsrepository.delete (SID); Studentsrepository.flush (); return"Redirect:/admin/students"; } @RequestMapping (Value= "/admin/students/update/{sid}", method =requestmethod.get) PublicString updatestudent (@PathVariable ("Sid") Integer SID, Modelmap Modelmap) {studententity studententity=Studentsrepository.findone (SID); Modelmap.addattribute ("Student", studententity); return"Admin/updatestudent"; } @RequestMapping (Value= "/admin/students/updatep", method =requestmethod.post) PublicString Updatestudentpost (@ModelAttribute ("STUDENTP") studententity studententity) {studentsrepository.updatestudent (Studententity.getsname (), Studententity.getssex (), Studententity.getsbirthday (), Studententity.getsphone ( ), Studententity.getsid ()); Studentsrepository.flush (); return"Redirect:/admin/students"; } @RequestMapping (Value= "/admin/teachers", method =requestmethod.get) PublicString getteachers (Modelmap modelmap) {List<TeacherEntity> teacherlist =Teacherrepository.findall (); Modelmap.addattribute ("Teacherlist", teacherlist); return"Admin/teachers"; } @RequestMapping (Value= "/admin/clazzs", method =requestmethod.get) PublicString Getclazzs (Modelmap modelmap) {List<ClazzEntity> clazzlist =Clazzrepository.findall (); Modelmap.addattribute ("Clazzlist", clazzlist); return"Admin/clazzs"; } @RequestMapping (Value= "/admin/teachers/add", method =requestmethod.get) PublicString Addteacher () {return"Admin/addteacher"; } @RequestMapping (Value= "/admin/teachers/addt", method =requestmethod.post) PublicString Addteacherpost (@ModelAttribute ("Teacher") teacherentity teacherentity) {Teacherrepository.saveandflush (teacherentity); return"Redirect:/admin/teachers"; } @RequestMapping (Value= "/admin/teachers/show/{tid}", method =requestmethod.get) PublicString Showteacher (@PathVariable ("Tid") Integer tid, Modelmap modelmap) {teacherentity teacherentity=Teacherrepository.findone (TID); Modelmap.addattribute ("Teacher", teacherentity); return"Admin/teacherdetail"; } @RequestMapping (Value= "/admin/teachers/delete/{tid}", method =requestmethod.get) PublicString Deleteteacher (@PathVariable ("Tid") {teacherrepository.delete (TID); Teacherrepository.flush (); return"Redirect:/admin/teachers"; } @RequestMapping (Value= "/admin/teachers/update/{tid}", method =requestmethod.get) PublicString Updateteacher (@PathVariable ("Tid") Integer tid, Modelmap modelmap) {teacherentity teacherentity=Teacherrepository.findone (TID); Modelmap.addattribute ("Teacher", teacherentity); return"Admin/updateteacher"; } @RequestMapping (Value= "/admin/teachers/update", method =requestmethod.post) PublicString Updateteacherpost (@ModelAttribute ("Teacher") teacherentity teacherentity) {teacherrepository.updateteacher (Teacherentity.gettname (), Teacherentity.gettsex (), Teacherentity.gettbirthday (), Teacherentity.gettphone (), Teacherentity.gettfield (), Teacherentity.gettqualificationlevel (), Teacheren Tity.gettemail (), TEACHERENTITY.GETTQQ (), Teacherentity.gettmsn (), teacherent Ity.gettid ()); Teacherrepository.flush (); return"Redirect:/admin/teachers"; } @RequestMapping (Value= "/admin/clazzs/show/{cid}", method =requestmethod.get) PublicString Showclazz (@PathVariable ("CID") Integer CID, Modelmap modelmap) {clazzentity clazzentity=Clazzrepository.findone (CID); Modelmap.addattribute ("Clazz", clazzentity); return"Admin/clazzdetail"; } @RequestMapping (Value= "/admin/clazzs/update/{cid}", method =requestmethod.get) PublicString Updateclazz (@PathVariable ("CID") Integer CID, Modelmap modelmap) {clazzentity clazzentity=Clazzrepository.findone (CID); Modelmap.addattribute ("Clazz", clazzentity); return"Admin/updateclazz"; } @RequestMapping (Value= "/admin/clazzs/update", method =requestmethod.post) PublicString Updateclazzpost (@ModelAttribute ("Clazz") clazzentity clazzentity) {Clazzrepository.updateclazz (Clazzentity.getcname (), Clazzen Tity.getcyear (), Clazzentity.getcid ()); Clazzrepository.flush (); return"Redirect:/admin/clazzs"; } @RequestMapping (Value= "/admin/clazzs/delete/{cid}", method =requestmethod.get) PublicString Deleteclazz (@PathVariable ("CID") (Integer CID) {clazzrepository.delete (CID); Clazzrepository.flush (); return"Redirect:/admin/clazzs"; } @RequestMapping (Value= "/admin/clazzs/add", method =requestmethod.get) PublicString Addclazz () {return"Admin/addclazz"; } @RequestMapping (Value= "/admin/clazzs/add", method =requestmethod.post) PublicString Addclazzpost (@ModelAttribute ("Clazz") clazzentity clazzentity) {Clazzrepository.saveandflush (clazzentity); return"Redirect:/admin/clazzs"; }}
Fourth Database Job--mainservlet section