1. 从数据库获取一列信息,呈现的前端网页上
适用环境:JAVA语言,SpringMvc框架
正文:
// 在controller层创建方法
// 显示用户管理 jsp页面的方法
@RequestMapping("/userManage.do")
public String showTaskManage(ModelMap modelMap) {
// 声明返回结果
List<User> userList = userService.getList();
// 将返回结果存放到页面 名为 “userList” 的变量中
modelMap.addAttribute("userList", userList);
// 转入到userManage ,刚才创建的jsp页面中
return "userList";
}
// 创建 JSP 页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>用户管理</title>
</head>
<body>
<!-- 正文 -->
<div class="container">
<!-- userList 是在controller层方法中设置的数据 -->
<c:forEach items="${userList }" var="user">
<!-- 注意在这里,c:forEach标签中 必须声明 var="xxx",才能在后文中,用xxx点出信息 -->
<div >
<p class="userName">${user.userName} </p> <p> </p>
</div>
</c:forEach>
</div>
</body>
</html>