Struts+ibatis-學習總結一
1查詢並返回list
別名映射->實體類:resultClass |
<select id=" selectAll" resultClass="AppLog"> select ID as id, TYPE as type, DESCR as descr from APP_LOG where ID = #id# </select> |
List list = sqlMapper.queryForList("selectAll"); for (int i = 0; i < list.size(); i ) { AppLog log = (AppLog) list.get(i); //add your code here; } |
別名映射->Map類:resultClass |
<select id=" selectAll" resultClass="java.util.HashMap"> select ID as id, TYPE as type, DESCR as descr from APP_LOG where ID = #id# </select> |
List list = sqlMapper.queryForList("selectAll"); for (int i = 0; i < list.size(); i ) { Map map = (Map) list.get(i); String id = (String) map.get("id"); String type = (String) map.get("type"); String descr = (String) map.get("descr"); //add your code here; } |
顯式映射->實體類:resultMap |
<resultMap id="AppLogResult" class="AppLog">
<result property="id" column="ID"/>
<result property="type" column="Type"/>
<result property="descr" column="DESCR"/>
</resultMap>
<select id="selectAll" resultMap="AppLogResult" |
List list = sqlMapper.queryForList("selectAll"); for (int i = 0; i < list.size(); i ) { AppLog log = (AppLog) list.get(i); //add your code here; } |
顯式映射->Map類:resultMap |
<resultMap id="map-result" class="java.util.HashMap"> <result property="id" column="ID"/> <result property="type" column="Type"/> <result property="descr" column="DESCR"/> </resultMap> <select id="selectAll2" resultMap="map-result"> select * from APP_LOG </select> |
List list = sqlMapper.queryForList("selectAll2"); for (int i = 0; i < list.size(); i ) { Map map = (Map) list.get(i); String id = (String) map.get("id"); String type = (String) map.get("type"); String descr = (String) map.get("descr"); } |
2,Unknown tag (c:forEach) 未知的標簽
需要在
<%@ page language="Java" import="java.util.*" pageEncoding="utf-8"%>下面加一句
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
3<c:foreach>
<c:forEach>標簽,需要與el表達式聯合使用
<c:forEach>標簽的語法定義如下所示。
<c:forEach var="每個變量名字" items="要叠代的list" varStatus="每個對象的狀態"
begin="循環從哪兒開始" end="循環到哪兒結束" step="循環的步長">
循環要輸出的東西
</c:forEach>
例如
<table border="1">
<tr><th>用戶名</th> <th>密碼</th> <th>操作</th></tr>
<c:forEach var="userlist" items="${userlist}">
<tr><th>${userlist.username}</th>
<th>${userlist.password}</th>
<th><a href="">修改</a> <a href="">刪除</a> </th></tr>
</c:forEach>
</table>
Struts+ibatis-學習總結一