美文网首页
页面传参和显示list(使用request)

页面传参和显示list(使用request)

作者: 青釉_5094 | 来源:发表于2017-06-30 22:22 被阅读0次

controller接受参数并设置页面里的结果,接受的参数与页面的设置有关

//这里写注解,不然扫描不到.do
@Controller  
public class WarehouseCheckController {

    @Autowired
    UserService ser;//要使用的service
    
    @RequestMapping(value="Warehouse_Check_ProductShelfRelation.do",method={RequestMethod.GET,RequestMethod.POST})
//value里指明这个函数对应的.do
//页面里的action跳转时设置action="Warehouse_Check_ProductShelfRelation.do"就转到这个函数来处理
    public ModelAndView linchao(HttpServletRequest request,Shelf sh){//这里加了HttpServletRequest参数,由页面传入,Shelf类由页面里的表单post而来
        
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("Warehouse_Check");
        
        List<User> list=ser.findAll();
        request.setAttribute("atrlist",list);//这里注入list类参数
        request.setAttribute("amount",13);//这里注入单个参数
        
        
        return modelAndView;
    }
}

在jsp页面的开头第二行加

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

通过form提交给controller参数

<form class="form-inline"
    action="${pageContext.request.contextPath}/Warehouse_Check_ProductShelfRelation.do"
    method="post"><!post提交表单给controller里对应的.do-->
    <div >
        <label>货架名</label> <input type="text"
            name="shel_name" ><!这里传给controller的参数是com.cqu.model包里的实体类的形式,shel_name在这里是Shelf类的属性-->
    </div>
    <div>
        <label>货架位置</label> <input type="text"
            name="shel_loc">
    </div>
    <div class="form-group filter-btn">
        <button class="btn btn-default">查询</button>
    </div>
</form>




table遍历一个list并动态添加显示出的行

    <tbody>
    <tr>
    
        <td>数量</td>
        <td>${requestScope.amount}</td><!--注入单个参数,controller中的request.setAttribut实现注入-->
    
    </tr>
        <c:forEach items="${requestScope.atrlist}" var="user" varStatus="status"> 
<tr>
    
    
    <td>status.index</td> <!--varStatus.index提供从零开始的行号--> 
    <td>${user.user_email}</td><!--读取实体类的属性时直接写属性名而不是调用get-->
    
</tr>
</c:forEach>  

    </tbody>

相关文章

  • 页面传参和显示list(使用request)

    controller接受参数并设置页面里的结果,接受的参数与页面的设置有关 在jsp页面的开头第二行加 通过for...

  • 问号传参和路径传参的区别

    问号(?)传参和路径传参的区别 问号传参需要使用问号来拼接参数,在接受方,使用request.getParamet...

  • 页面传参到模态框控制显示内容

    勋章页面传参到显示勋章获得条件

  • Next.js 跳转传参并接收接参

    介绍路由传参,接参使用方法 传参 + 跳转页面接收参数 动态路由传参 + 跳转页面接收参数创建动态路由在pag...

  • 路由传参

    params传参(刷新页面后参数不消失,参数会在地址栏中显示) query传参(刷新后页面参数丢失) state传...

  • vue-router 传参

    动态操作路由 注意:前者query传参,会在页面url上显示参数,后者params传参则不会,这代表刷新页面前者参...

  • Mybatis

    1.传参数:List类型,SQL中直接使用#{list}多个参数传参时,可以使用Map , 存放的Key是SQL中...

  • vue - 路由带参跳转

    vue路由传参按照传参方式可划分为params传参和query传参; params传参分为在url中显示和影藏参数...

  • Django常见数据类型提交、解析与响应

    Request请求 http协议向客户端传参四种形式 URL地址拼接传参传参示例:传递名字和年龄http://12...

  • Thymleaf使用th:each遍历

    使用该标签完成list或map数据的遍历 后台传参 标准的springmvc传参的方式,见如下代码: 解释 使用m...

网友评论

      本文标题:页面传参和显示list(使用request)

      本文链接:https://www.haomeiwen.com/subject/emoicxtx.html