我有两个页面:搜索页面和编辑页面(jsp文件)。搜索页面用于搜索和显示项目列表。编辑页面用于编辑项目。
在搜索页面中,我有一个项目编号的链接,用于导航到编辑页面。
当用户成功编辑项目时,他们将被重定向到搜索页面。
我的问题是如何让搜索页面立即显示最新项目而无需刷新或再次搜索?我正在使用hibernate + spring mvc。
提前感谢您的帮助!
答案 0 :(得分:0)
我认为它能完成这项工作。通过会话将搜索模式传递给编辑操作。因此,您可以在重定向到搜索页面时显示更新的搜索结果。
@Controller
public class ProjectsController {
@RequestMapping(value = "edit", method = RequestMethod.POST)
String doEditProject(HttpSession httpSession, @ModelAttribute Project p ) {
// persist the edited project
// redirect to search page with last search word
String searchPattern = (String) httpSession.getAttribute("search_pattern");
return "redirect:search?pattern=" + searchPattern;
}
@RequestMapping(value = "search", method = RequestMethod.GET)
String displaySearch(@RequestParam(value = "pattern", required = false) String searchPattern, ModelMap model, HttpSession httpSession) {
if (searchPattern == null) {
// display empty search view
return "searchView";
} else {
// search using the pattern
// put model and create links like edit?project_id=xx
httpSession.setAttribute("search_pattern", searchPattern);
return "searchView";
}
}
}