el表达式是jsp独有的接收后台传输数据的方法,用el表达式会更安全与效率,而在这里我后台是用ModelAndView进行的数据传输。
我这里就用个简单的例子作为演示。
ModelAndView:
@RequestMapping("/test/{id}") public ModelAndView test( HttpServletRequest request,@PathVariable long id){ Condition cond= RequestUtils.buildCondition(request, Notify.class); PageHelper.startPage( (int)id, 15); List<Notify> list = notifyManager.find(Notify.class,cond);//将数据提取出list ModelAndView mav=new ModelAndView("welcome");//这里用来跳转到所需要到达的页面 mav.addObject("list", list);//传给前台一个list参数 return mav; }
前台的el表达式:
${requestScope.list}
将el表达式与c:forEach配合使用:
<c:forEach items="${requestScope.list}" var="allList" begin="0" end="14"> <div style="background-color: #00B83F;color: #1a1a1a"><c:out value="${allList.title}"/></div> </c:forEach>其中items是用来接收数据,var是给数据打包起个名字,begin与end是循环起始与结束的位置,c:out就是进行循环出的具体的数据
这样就可以把后台传输的list显示在前台页面。
这是本人的第一篇文章,主要目的是为了给自己用过的知识做笔记并且与各位分享一下,本人水平并不高,还望各位大神能给与指点。