springmvc跳转页面的几种放方法
来源:互联网 发布:java转义html特殊字符 编辑:程序博客网 时间:2024/06/05 06:59
Springmvc跳转页面的几种方法@Controller//为了对url进行分类管理 ,可以在这里定义根路径,最终访问url是根路径+子路径//比如:商品列表:/items/queryItems.action@RequestMapping("/items")public class ItemsController {@Autowiredprivate ItemsService itemsService;// 商品查询@RequestMapping("/queryItems")//第一种使用ModelAndViewpublic ModelAndView queryItems(HttpServletRequest request) throws Exception {//测试forward后request是否可以共享System.out.println(request.getParameter("id"));// 调用service查找 数据库,查询商品列表List<ItemsCustom> itemsList = itemsService.findItemsList(null);// 返回ModelAndViewModelAndView modelAndView = new ModelAndView();// 相当 于request的setAttribut,在jsp页面中通过itemsList取数据modelAndView.addObject("itemsList", itemsList);// 指定视图// 下边的路径,如果在视图解析器中配置jsp路径的前缀和jsp路径的后缀,修改为// modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");// 上边的路径配置可以不在程序中指定jsp路径的前缀和jsp路径的后缀modelAndView.setViewName("items/itemsList");return modelAndView;}//商品信息修改页面显示//@RequestMapping("/editItems")//限制http请求方法,可以post和get//@RequestMapping(value="/editItems",method={RequestMethod.POST,RequestMethod.GET})//public ModelAndView editItems()throws Exception {//////调用service根据商品id查询商品信息//ItemsCustom itemsCustom = itemsService.findItemsById(1);////// 返回ModelAndView//ModelAndView modelAndView = new ModelAndView();//////将商品信息放到model//modelAndView.addObject("itemsCustom", itemsCustom);//////商品修改页面//modelAndView.setViewName("items/editItems");////return modelAndView;//}@RequestMapping(value="/editItems",method={RequestMethod.POST,RequestMethod.GET})//@RequestParam里边指定request传入参数名称和形参进行绑定。//通过required属性指定参数是否必须要传入//通过defaultValue可以设置默认值,如果id参数没有传入,将默认值和形参绑定。//通过继承Modelpublic String editItems(Model model,@RequestParam(value="id",required=true) Integer items_id)throws Exception {//调用service根据商品id查询商品信息ItemsCustom itemsCustom = itemsService.findItemsById(items_id);//通过形参中的model将model数据传到页面//相当于modelAndView.addObject方法model.addAttribute("itemsCustom", itemsCustom);return "items/editItems";}//商品信息修改提交@RequestMapping("/editItemsSubmit")//第三种.使用直接跳转,但是不能传递需要参数public String editItemsSubmit(HttpServletRequest request,Integer id,ItemsCustom itemsCustom)throws Exception {//调用service更新商品信息,页面需要将商品信息传到此方法itemsService.updateItems(id, itemsCustom);//重定向到商品查询列表//return "redirect:queryItems.action";//页面转发//return "forward:queryItems.action";return "success";}}
阅读全文
0 0
- springmvc跳转页面的几种放方法
- springmvc跳转页面的方法
- SpringMVC的页面跳转
- 页面跳转的方法
- 页面跳转的方法
- 页面跳转的方法
- Springmvc几种页面跳转的方式
- springmvc和easyUI下的页面跳转
- springMVC 跳转到页面
- SpringMvc 页面跳转
- SpringMVC统一异常处理(返回异常数据而不是跳转到某个页面的方法)
- SpringMVC统一异常处理(返回异常数据而不是跳转到某个页面的方法)
- Javascript跳转页面的方法
- 页面跳转的各种方法
- php页面跳转的方法
- flex 页面跳转的方法
- 页面跳转的方法收集
- servlet跳转页面的方法
- 将图片资源转化为Bitmap的多种方法
- iOS 分组的CollectionView
- QT+VS点击按钮弹出新窗口的实现
- 解决--android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
- Almost Palindrome UVA
- springmvc跳转页面的几种放方法
- android之 eventBus简单实用
- android webview Not allowed to load local resource错误的解决办法
- com.sun.jdi.internalException:Unexpected JDWP Error:103////Method threw 'java.lang.IllegalArgumentEx
- List 排序
- 去掉ng-repeat产生的$$hashkey和object
- 通过hadoop自带的demo运行单词统计
- ORA-00020: maximum number of processes (150) exceeded
- iOS截取特定区域的图片,然后拼接起来,可在图片上定制任意控件