-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllersClass.java
More file actions
141 lines (120 loc) · 4.04 KB
/
ControllersClass.java
File metadata and controls
141 lines (120 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.ProjectStudent.CollegeWebApp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class ControllersClass {
@Autowired
Dao data;
@GetMapping(value="/home")
public String homePage() {
return "HomeHt";
}
@RequestMapping(value="/info")
public String infoPage() {
return "infoHt";
}
@GetMapping(value="/home/studentData")
public String studentData(Model mod) {
List<Student> lis= data.allStudents();
mod.addAttribute("listst", lis);
return "Viewstudent";
}
@GetMapping(value="/home/admin")
public String homePag12e() {
return "AdminHt";
}
@PostMapping(value="/home/admin")
public String adminPage(@RequestParam String name,String Password,ModelMap mod) {
Admin adm=data.getAdmin(name);
if(adm==null) {
mod.addAttribute("message","Your User Name is Invalid");
return "HomeHt";
}
else if(Password.equals(adm.getPassword())) {
mod.addAttribute("adm", adm);
return "AdminHt";
}
else {
mod.addAttribute("message","Your Password is Invalid");
return "HomeHt";
}
}
@PostMapping(value="/home/student")
public String studentPage(@RequestParam int roll,String password,Model mod) {
Student stud=data.findStudent(roll);
if(stud==null) {
mod.addAttribute("message", "Your UserName is Invalid" );
return "HomeHt";
}
else if(password.equals(stud.getPassword())) {
mod.addAttribute("stud", stud);
return "studentHt";
}
else {
mod.addAttribute("message", "Your Password is Invalid" );
return "HomeHt";
}
}
@GetMapping(value="/home/admin/addAdmin")
public String addAdmin() {
return "NewAdmin";
}
@PostMapping(value="/home/admin/addAdmin")
public String newAdmin(@ModelAttribute("admin") Admin admin, Model mod) {
Admin adm=data.getAdmin(admin.getUsername());
if(adm==null) {
data.addAdmin(admin);
mod.addAttribute("message","Added ");
mod.addAttribute("name",admin.getName());
}
else {
mod.addAttribute("message","Invalid User Name, Details with the same user name Already exist");
mod.addAttribute("name",admin.getUsername());
}
return "NewAdmin";
}
@GetMapping(value="/home/admin/addStudent/{name}")
public String addStudent(@PathVariable String name,Model mod) {
mod.addAttribute("tag", name);
return "NewStudent";
}
@PostMapping(value="/home/admin/addStudent/{tag}")
public String newStudent(@ModelAttribute("stud") Student stud, @PathVariable String tag,Model mod) {
Student chk=data.findStudent(stud.getRoll());
if(chk==null) {
data.addStudent(stud);
data.addAdminStudent(tag, stud);
mod.addAttribute("message","Added "+stud.getName());
}
else {
mod.addAttribute("message","Invalid Roll no"+ stud.getRoll() +"Details with the same Roll no Already exist");
}
return "NewStudent";
}
@GetMapping(value="/home/admin/viewStudent/{name}")
public String adminViewStudent(@PathVariable String name ,Model mod) {
Admin admin=data.getAdmin(name);
List<Student> list=admin.getList();
mod.addAttribute("list", list);
mod.addAttribute("admin", name);
return "AdminStudentsHt";
}
@GetMapping(value="/home/admin/viewAdmin")
public String adminviewAdmin(Model mod) {
List<Admin> list=data.allAdmins();
mod.addAttribute("list", list);
return "AllAdminHt";
}
}