在我的系统中,当用户选择一个学生组(例如CS Year1)时,应该为该学生组加载时间表视图。有人可以告诉我该如何做。谢谢
我创建了时间表视图(所有视图都一样),还选择了带有下拉菜单和“提交”按钮的时间表页面。
选择时间表视图
<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">
<head>
<link rel="stylesheet" type="text/css" href="static/css/add.css" th:href="@{/css/add.css}">
<meta charset="UTF-8">
<title>New Time Table</title>
</head>
<body>
<h1>New Time Table</h1>
<div class="container" style="margin-top:30px">
<img src="static/img/books.jpeg" th:src="@{/img/books.jpeg}"/>
<div class="container2">
<form action="#" th:action="@{/timeTable/select}" th:object="${timeTable}" method="post">
<table border="0" cell[adding="10">
<tr>
<td>Student Group:</td>
<td>
<select th:field="*{group_code}">
<option value="">Choose..</option>
<option th:each="studentGroup: ${studentGroups}" th:value="${studentGroup.group_code}"
th:text="${studentGroup.group_code}"/>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit">Select</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
时间表视图
<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">
<head>
<link rel="stylesheet" type="text/css" href="static/css/timetable.css" th:href="@{/css/view.css}">
<meta charset="UTF-8">
<title>Time Table</title>
</head>
<body>
<h1>Time Table</h1>
<div class="container" style="margin-top:30px">
<br><br>
<table border="1">
<thead>
<tr>
<td></td>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>
<tbody>
<tr th:each="subject : ${subjectDetails}">
<td> 8.00 - 9.00</td>
</tr>
<tr><td> 9.00 - 10.00</td>
</tr>
<tr> <td>10.00 - 11.00</td>
</tr>
<tr><td>11.00 - 12.00</td>
</tr>
<tr> <td>12.00 - 1.00</td>
</tr>
<tr> <td>1.00 - 2.00</td>
</tr>
<tr><td> 2.00 - 3.00</td>
</tr>
<tr><td> 3.00 - 4.00</td>
</tr>
<tr><td> 4.00 - 5.00</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
时间表控制器
@Controller
public class TimeTableController {
@Autowired
private TimeTableDAO timeTableDAO;
@Autowired
private SubjectDAO subjectDAO;
@Autowired
private StudentGroupDAO studentGroupDAO;
@RequestMapping("/timeTable")
public String viewHomePage(Model model){
TimeTable timeTable =new TimeTable();
model.addAttribute("timeTable",timeTable);
List<StudentGroup> studentGroupDetail = studentGroupDAO.findAll();
model.addAttribute("studentGroups", studentGroupDetail);
return "timeTable";
}
@RequestMapping("/timeTable/select")
public String addTimeTable(Model model){
TimeTable timeTable =new TimeTable();
model.addAttribute("timeTable",timeTable);
List<Subject> subjectDetail = subjectDAO.findAll();
model.addAttribute("subjects", subjectDetail);
List<StudentGroup> studentGroupDetail = studentGroupDAO.findAll();
model.addAttribute("studentGroups",studentGroupDetail);
return "timeTableView";
}
@RequestMapping(value="/timeTable/save",method= RequestMethod.POST)
public String saveTimeTable(@ModelAttribute("timeTable") TimeTable timeTable){
timeTableDAO.save(timeTable);
return "redirect:/timeTable";
}
@RequestMapping("/timeTable/edit/{id}")
public ModelAndView updateTimeTable(@PathVariable(name="id")Long id){
ModelAndView mav=new ModelAndView(("updateTimeTable"));
TimeTable timeTable = timeTableDAO.findById(id);
mav.addObject("timeTable",timeTable);
List<Subject> subjectDetail = subjectDAO.findAll();
mav.addObject("subjects", subjectDetail);
List<StudentGroup> studentGroupDetail = studentGroupDAO.findAll();
mav.addObject("studentGroups",studentGroupDetail);
return mav;
}
@RequestMapping("/timeTable/delete/{id}")
public String deleteProduct(@PathVariable(name="id") Long id){
timeTableDAO.delete(id);
return "redirect:/timeTable";
}
}