ibatis查询结果为null
我照着ibatis的导读的例子做的,但采用struts+ibatis架构,表
person:
per_id:编号
per_first_name:第一个名
per_last_name:最后一个名
per_birth_date:出生日期,datetime
per_weight_kg:体重
per_height_m:身高
sqlmap配置文件sql_map_config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="myconfig/database.properties" />
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<transactionManager type="JDBC" >
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
</dataSource>
</transactionManager>
<sqlMap resource="myconfig/person.xml" />
</sqlMapConfig>
sqlmap映射文件person.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Person">
<resultMap class="example.domain.Person" id="map_person">
<result property="id" column="per_id"></result>
<result property="firstName" column="per_first_name"></result>
<result property="lastName" column="per_last_name"></result>
<result property="birthDate" column="per_birth_date"></result>
<result property="weight" column="per_column_kg"></result>
<result property="height" column="per_height_m"></result>
</resultMap>
<select id="getPerson" resultMap="map_person"
parameterClass="int">
select per_id as id,per_first_name as firstName,
per_last_naem as lastName,per_birth_date as birthDate,
per_weight_kg as weight,per_height_m as height
from person where per_id=#value#
</select>
<select id="getAllPerson" resultMap="map_person">
<![CDATA[
select * from person
]]>
</select>
<insert id="insertPerson" parameterClass="example.domain.Person">
insert into person (per_id,per_first_name,per_last_name,
per_birth_date,per_weight_kg,per_height_m)
values (#id#,#firstName#,#lastName#,#birthDate#,#weight#,
#height#)
</insert>
<update id="updatePerson" parameterClass="example.domain.Person">
update person set per_first_name=#firstName#,
per_last_name=#lastName#,per_birth_date=#birthDate#,
per_weight_kg=#weight#,per_height_m=#height#
where per_id=#id#
</update>
<delete id="deletePerson" parameterClass="example.domain.Person">
delete from person where per_id=#id#
</delete>
</sqlMap>
我在一个action里调用queryForList,然后赋值给一个List时,竟然报错。
dao的源代码:
package daos;
import java.sql.SQLException;
import example.domain.*;
import com.ibatis.sqlmap.client.*;
import java.util.*;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class PersonDAO {
private SqlMapClient client;
public PersonDAO(SqlMapClient client)
{
this.client=client;
}
public void insert(Person person) {
try {
client.startTransaction();
client.insert("Person.insertPerson",person);
client.commitTransaction();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void update(Person person) {
try {
client.startTransaction();
client.update("Person.updatePerson",person);
client.commitTransaction();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void delete(int id)
{
//client.delete("Person.delete",person);
}
public Person findById(int id)
{
Person rst=null;
try {
rst=(Person)(client.queryForObject("Person.getPerson",new Integer(id)));
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return rst;
}
public List findAll()
{
List list=null;
try {
list=client.queryForList("Person.getAllPerson",null);
int i;
i=0;
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
finally
{
return list;
}
}
}