document.location.href=BASE_PATH +'test/index?id='+id;
Java代码
@RequestMapping(value = "/test/view/{id}", method = { RequestMethod.GET, RequestMethod.POST })
public @ResponseBody ModelAndView view(HttpServletRequest request, @PathVariable Long id) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
TestEntity ttest = testService.getTestById(id);
if(test == null){
return returnModelAndView(request,"errors/error",map);
}
map.put("test",test);
return returnModelAndView(request, "/test/view", map);
}
得引用 import org.springframework.web.servlet.ModelAndView; 包
本文介绍了一个使用SpringMVC框架处理视图请求的具体方法,包括如何通过@RequestMapping注解映射URL路径,以及如何利用ModelAndView对象返回视图和数据。同时展示了如何处理不存在的数据ID时返回错误页面。
1343

被折叠的 条评论
为什么被折叠?



