我正在使用 spring 框架实现一个公告板。
为了显示有关 jsp 的文章列表,我从 DB 获取了一些信息并将其保存到List<BulletinBoardList>
.
我想要做的就是把这个List拿到jsp中保存。我尝试使用以下代码:
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
/*
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
*/
List<BulletinBoardList> result = sqlSession.selectList("board.getList");
model.addAttribute("list", result);
return "home";
}
接下来,此代码用于从控制器检索列表:
<%@ page import com.heesu.third.BulletinBoardList, java.util.List %>
<% BulletinBoardList list = ${list} %>
但它永远不会奏效。
我在jsp中使用jstl做过这样的事情。看看我的代码。这里我的列表是“inf”,我的对象有不同的领域,但我认为你会设法适应它:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Real time info</title>
<link href="webjars/bootstrap/3.3.6/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<table class="table table-striped">
<caption><h3>Result (People):</h3></caption>
<thead>
<tr class="tr tr-success">
<td>Id</td>
<td>Name</td>
<td>PIN</td>
</tr>
</thead>
<tbody>
<c:forEach items="${inf}" var="temp">
<tr>
<td>${temp.id}</td>
<td>${temp.name}</td>
<td>${temp.pin}</td>
<td>
<a class="btn btn-info" href="/update-person?id=${temp.id}">Update</a>
<a class="btn btn-danger" onclick="return confirm('Are you sure you want to delete?')" href="/delete-person?id=${temp.id}">Delete</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<script src="webjars/jquery/2.2.4/jquery.min.js"></script>
<script src="webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>
这是控制器的特定部分:
@RequestMapping(value = "/search", method = RequestMethod.POST)
public String handleRequest(@RequestParam String search,
ModelMap model){
List<UserInfo> inf = searchServ.listPeople(search);
model.put("inf", inf);
return "info";
}
你的情况非常相似。我希望这会帮助你。只是补充一下 - 我正在使用引导程序来设计我的图形用户界面。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句