JSP页面读取不到 Map中的数据

狼王_ 2017-05-23 03:36:32
在JSP页面中无法读取到数据,挑战到 list.jsp 后一片空白。。代码如下
我在 EmployeeHandler 中定义的方法如下:
@RequestMapping("/emps")
public String list(Map<String,Object> map){
map.put("employees", employeeDao.getAll());
return "list";
}
在JSP页面中读取数据如下:
<c:if test="${ empty requestScope.employees }">
没有任何员工信息。
</c:if>
<c:if test="${ !empty employees }">
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>ID</th>
<th>LastName</th>
<th>Email</th>
<th>Gender</th>
<th>Department</th>
<th>Edit</th>
<th>Delete</th>
</tr>

<c:forEach items="${requestScope.employees}" var="emp">
<tr>
<th>${emp.id}</th>
<th>${emp.lastName}</th>
<th>${emp.email}</th>
<th>${emp.gender==0?'Female':'Male'}</th>
<th>${emp.department.departmentName}</th>
<th><a href="">Edit</a></th>
<th><a href="">Delete</a></th>
</tr>
</c:forEach>
</table>
</c:if>
...全文
450 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcoderz 2017-05-24
  • 打赏
  • 举报
回复
方法写的不对,springmvc是将得到的结果添加到model里面,然后再return到view。楼主 的map没有添加到model中

@RequestMapping("/stu")
public String query(Model model) {
        model.addAttribute("employees", employeeDao.getAll());
        return "list";
 }
[/code]
rookie_s 2017-05-24
  • 打赏
  • 举报
回复
1.检查实体传到页面之后是否赋上值 2.页面用el表达式取的话直接可以点出来。
samin_zou 2017-05-24
  • 打赏
  • 举报
回复
第一,楼主先确定employeeDao实体来源哪里,是否有数据 第二,你返回的是Map,不是list,所以jsp上面不需要用foreach循环的 第三,requestScope.employees 可以不这么取值 直接类似 ${employees.id}就可以了
  • 打赏
  • 举报
回复
我也觉得是返回的东西错了,就算是返回集合加上“”是不是返回成了”list”字符串了?
_jant 2017-05-23
  • 打赏
  • 举报
回复
老铁你的数据根本没带到页面。
tawift 2017-05-23
  • 打赏
  • 举报
回复
import org.springframework.ui.Model; @RequestMapping("/emps") public String list(Model model){ model.addAttribute("employees", employeeDao.getAll()); return "list"; }
李德胜1995 2017-05-23
  • 打赏
  • 举报
回复
把方法改了、。。。

@RequestMapping("/emps")
public ModelAndView list(){
ModelAndView view=new ModelAndView("list");
view.addObject("employees", employeeDao.getAll());
return view;
}
遍历使用
<c:forEach items="${employees}" var="emp">就可以了。。。。
cwpcando 2017-05-23
  • 打赏
  • 举报
回复
你确定数据传到页面了?
FatMouse111 2017-05-23
  • 打赏
  • 举报
回复

下面这个要跟上面的写法一样

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧