zoukankan      html  css  js  c++  java
  • SpringMVC域对象数据输出

    在request、session、application雨中保存数据,进行数据的传递:

    SpringMVC除了可以在方法上传入request和session外还能怎么样吧数据带给页面:

      1、方法返回值是String,可以在方法出传入Map、Model、ModelMap。这些参数里面保存的所有数据都会放在request域中,可以在页面获取;

        关系:Map、Model、ModelMap,最终都是BindingAwareModelMap在工作;相当于在BindingAwareModelMap中保存的东西都会被放在请求域中;

        Map(interface[jdk])  Model(interface[Spring])  

        

    @RequestMapping("input")
    public String input(Map map, ModelMap modelMap, Model model){
        map.put("msg","hello") ;
        modelMap.addAttribute("name","word") ;
        model.addAttribute("age",17) ;
        return "message/index" ;
    }

      2、方法的返回值可以变为ModelAAndView属性:

        即包含视图信息(页面地址)也包含模型数据(给页面带的数据),而且数据时放在请求域中;

    @RequestMapping("input")
    public ModelAndView input(HttpServletRequest request , HttpServletResponse response){
        ModelAndView modelAndView = new ModelAndView("message/index");
        modelAndView.addObject("msg","hello") ;
        return modelAndView ;
    }

      3、给session域中保存数据:

    @RequestMapping("input")
    public ModelAndView input(){
        HttpSession session = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getSession() ;
        session.setAttribute("msg","hello");
        return new ModelAndView("message/index") ;
    }

     

  • 相关阅读:
    C语言:线程同步之信号量(sem_init,sem_post,sem_wait)
    SVN使用 -work
    atomic c++ y原子变量 替换锁代码
    原子变量
    perf
    内存泄露检测工具对比
    valgrind ----直接使用参数
    堆内存分析---特别棒
    调不尽的内存泄漏,用不完的 Valgrind(转)
    静态库动态库制作方法
  • 原文地址:https://www.cnblogs.com/luliang888/p/11073623.html
Copyright © 2011-2022 走看看