Springboot-jpa-thymeleaf -bootstrap。使用模态表单更新字段后,如何刷新过滤的表内容
我有一个带有以下控制器代码的项目表,
@RequestMapping(method = RequestMethod.GET)
public String listProjects(Model model){
model.addAttribute("projects", this.projectService.getProjects());
return "my-projects";
}
我选择一行以显示与项目关联的作业列表,
@RequestMapping (value = "/getAssignmentsByProjectId", method = {RequestMethod.GET})
public String getAssignmentsById(Model model, Long id) {
model.addAttribute("header", "Assignments for Project - " + this.projectService.getProjectNameById(id));
model.addAttribute("assignments", this.assignmentService.getAssignmentsByProjectId(id));
return "project-assignments";
}
然后编辑一行以使用模态表单和一些JS更改值
@RequestMapping("/getAssignmentById")
@ResponseBody
public Assignment getAssignmentById(Long id) {
Assignment assignment = this.assignmentService.getAssignmentById(id);
return assignment;
}
,然后我将更新写回到模式形式的数据库
@RequestMapping("/updateAssignment")
public String getAssignmentById(Long id, Double rate){
this.assignmentService.updateAssignmentById(id,rate);
return "project-assignments";
}
模态关闭,而我的作业列表现在没有行。
如何刷新仍然由同一ProjectID过滤的作业列表?
I have a table of projects populated with the below Controller code
@RequestMapping(method = RequestMethod.GET)
public String listProjects(Model model){
model.addAttribute("projects", this.projectService.getProjects());
return "my-projects";
}
I select a row to display a list of Assignments associated with a project
@RequestMapping (value = "/getAssignmentsByProjectId", method = {RequestMethod.GET})
public String getAssignmentsById(Model model, Long id) {
model.addAttribute("header", "Assignments for Project - " + this.projectService.getProjectNameById(id));
model.addAttribute("assignments", this.assignmentService.getAssignmentsByProjectId(id));
return "project-assignments";
}
I then edit a row to change a value using a Modal Form and some JS
@RequestMapping("/getAssignmentById")
@ResponseBody
public Assignment getAssignmentById(Long id) {
Assignment assignment = this.assignmentService.getAssignmentById(id);
return assignment;
}
Then I write the update back to the database from the modal form
@RequestMapping("/updateAssignment")
public String getAssignmentById(Long id, Double rate){
this.assignmentService.updateAssignmentById(id,rate);
return "project-assignments";
}
The modal closes and my list of assignments now has no rows.
How do I refresh the list of assignments, still filtered by the same ProjectId?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,那么您会执行AJAX请求以获取在模式对话框中显示的信息,并使用常规表单帖子实际更新信息。
我猜该片段:
应该这样完成:
这将在更新后将用户重定向到正确的URL,以显示给定项目ID的作业。
If I understand your question correctly, then you do an AJAX request to get the information to show in the modal dialog and you use a regular form POST to actually update the information.
I guess that this snippet:
should be done like this:
This would redirect the user after the update to the correct URL to show the assignments for a given project id.