zoukankan      html  css  js  c++  java
  • 【转】SpringMVC框架实现后端向前端传数据

    首先还是页面userAdd.jsp。它既是发出请求的页面,也是接收返回结果的页面:

    <%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
    <html>
      <head>
        <title></title>
      </head>
      <body>
        <h1>添加用户信息4</h1>
        <form action="user/add4.do" method="post">
            <input type="submit" value="提交">
        </form>
        ${personId }
      </body>
    </html>
    1、通过request对象:
    @RequestMapping("/add")
    public String add(HttpServletRequest request){
        request.setAttribute("personId",12);
        return "userAdd";
    }
    2、通过ModelAndView对象:
    @RequestMapping("/add")
    public ModelAndView add(){
        ModelAndView mav = new ModelAndView("userAdd");
        mav.addObject("personId", 12);
        return mav;
    }
    3、通过Model对象:
    @RequestMapping("/add")
    public String add(Model model){
        model.addAttribute("personId", 12);
        return "userAdd";
    }
    4、通过Map对象:
    @RequestMapping("/add")
    public String add(Map<String,Object> map){
        map.put("personId", 12);
        return "userAdd";
    }

    原文链接:https://blog.csdn.net/qq_31634461/article/details/81119228

  • 相关阅读:
    hdu4273Rescue(三维凸包重心)
    hdu4449Building Design(三维凸包+平面旋转)
    hdu3847Trash Removal(凸包)
    CodeForces 166B (凸包)
    机器学习文章导航
    梯度下降法深入
    插值法
    离散系统频域分析
    离散系统时域分析
    连续系统频域分析
  • 原文地址:https://www.cnblogs.com/steveshao/p/11777766.html
Copyright © 2011-2022 走看看