zoukankan      html  css  js  c++  java
  • Spring 作用域传值

        /**
         * 
         * @param request 可以把原生servlet有的东西写在参数里,response,session等
         * @param map 可以存在Map中
         * @param model 可以存在model接口对象 中
         * @return 跳转到一个jsp页面,因为配置了视图定位,所以只要号index
         */
        @RequestMapping("demo13")
        public String demo13(HttpServletRequest request,Map<String,String> map,Model model) {
            request.setAttribute("request", "requestName");
            request.getSession().setAttribute("session", "sessionName");
            request.getServletContext().setAttribute("application","applicationName");
            //SpringMVC会把map放在request中
            map.put("map", "mapName");
            model.addAttribute("model","modelName");
            
            return "index";
        }

    在jsp中用el表达示取出:

         <body>
             request:${requestScope.request }<br/>
             session:${sessionScope.session }<br/>
             application:${applicationScope.application }<br/>
             map:${requestScope.map }<br/>
             model:${requestScope.model }<br/>
         </body>

    使用ModelAndView类:

        @RequestMapping("demo14")
        public ModelAndView demo14() {
            //new ModeAndVie()的参数代表要进行跳转的路径
            ModelAndView mode = new ModelAndView("index");
            //存入一条数据。存在request中
            mode.addObject("modeAndView","modeAndView");
            return mode;
        }
  • 相关阅读:
    react-native 点击按钮进行交互
    常用类
    js里面 undefined 和 null
    ajax 提交数据
    通过Unicode判断一个字符是不是汉字
    git commit 后的对话框
    vue-cli 使用less的方法
    node创建服务器简单测试接口
    bootstrap3 模态框js的控制
    鱼眼镜头的坐标变换
  • 原文地址:https://www.cnblogs.com/lastingjava/p/10014839.html
Copyright © 2011-2022 走看看