首页 > 代码库 > Struts+ibatis-学习总结一
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">
select * from APP_LOG
</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类: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-学习总结一