今天遇到一个问题:
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/inspur/paas/attachment/dao/attachment.xml.
--- The error occurred while applying a result map.
--- Check the Attachment.getAppAttachmentByAppId-AutoResultMap.
--- Check the result mapping for the 'id' property.
--- Cause: java.lang.RuntimeException: JavaBeansDataExchange could not instantiate result class. Cause: java.lang.InstantiationException: java.util.Map
<select id="getAppAttachmentByAppId" parameterClass="string" resultClass="hashmap">
select app_id,email,attachment_id,id from gov_item_express_info where app_id = #app_id#
</select>
resultClass="hashmap" ---使用map报错
ibatis结果集resultClass的几种类型
http://www.jcodecraeer.com/a/chengxusheji/java/2013/0102/771.html
摘要 ibatis在编写sqlmap的查询时,可以配置多种输出格式,比如:实体类,hashmap,xml格式。 sqlmap中的hashmap和xml都是内置别名。 1.实体类: resultMap id="UserResult" class="User"result property="id" column="T_ID"/result property="name" column="T_NA
ibatis在编写sqlmap的查询时,可以配置多种输出格式,比如:实体类,hashmap,xml格式。
sqlmap中的hashmap和xml都是内置别名。
1.实体类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<resultMap id= "UserResult" class= "User" >
<result property= "id" column= "T_ID" />
<result property= "name" column= "T_NAME" />
<result property= "sex" column= "T_SEX" />
<result property= "address" column= "T_ADDRESS" />
</resultMap>
<select id= "selectAllUser" resultMap= "UserResult" > select * from t_user </select>
List list = userdao.selectAllUser(); for (int i=0;i<list.size();i++) { System.out.println(list.get(i)); }
|
注:当作一个对象使用。
2.hashmap:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<select id= "selectAllUser" resultClass= "hashmap" > select * from t_user </select>
List list = userdao.selectAllUser();
for (int i=0;i<list.size();i++) {
Map map = (Map)list.get(i);
System.out.print(map.get( "id" )+ " " );
System.out.print(map.get( "name" )+ " " );
System.out.print(map.get( "sex" )+ " " );
System.out.print(map.get( "address" ));
System.out.println();
}
|
注:当作一个键值对的MAP使用。
3.XML:
1
2
3
4
5
6
7
8
|
<select id= "selectXML" resultClass= "xml" xmlResultName= "log" > select * from t_user </select>
List list = userdao.selectAllUser();
for (int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}
|
XML结果:
1
2
3
4
|
<?xml version= "1.0" encoding= "UTF-8" ?><log><id>1</id><name>hua</name><***>1</***><address>1</address></log>
<?xml version= "1.0" encoding= "UTF-8" ?><log><id>2</id><name> zhupan </name><***>2</***><address>1</address></log>
<?xml version= "1.0" encoding= "UTF-8" ?><log><id>4</id><name> 4 </name><***>4</***><address>1</address></log>
<?xml version= "1.0" encoding= "UTF-8" ?><log><id>5</id><name> 5 </name><***>5</***><address>2</address></log>
|
分享到:
相关推荐
<select id="getDynamicTable" resultClass="java.util.HashMap" remapResults="true" parameterClass="java.lang.Integer"> select t.* from some_table t where t.status = #{status} ``` 这里需要注意的是,`#...
resultClass="java.util.HashMap" remapResults="true"> select $fieldnames$ from $resourcetable$ where 1=1 <include refid="select_data_by_condition"/> ``` 这里的 `<select>` 标签定义了一个查询语句,...
- `<select id="selectHashmap" parameterClass="int" resultClass="hashmap">`:定义查询操作。 - `select * from sexs, aawhere s.sid = a.aid and s.sid = #sid#`:联表查询。 - `<select id="selectAADyna" ...
<procedure id="P_DJ_GETRYANDPYRBYRYID" parameterMap="parameterDJRYID" resultClass="java.util.HashMap"> {call P_DJ_GETRYANDPYRBYRYID(?)} ``` 这里出现了一个问题,就是当只有一个问号`?`时,iBATIS默认...
本文将详细介绍如何在ibatis中实现多参数查询,并探讨几种常见的解决方案。 #### 二、ibatis简介 ibatis(现更名为MyBatis)是一个优秀的持久层框架,它消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索...
<select id="com.fashionfree.stat.accesslog.model.StatMemberAction.selectActionIdsOfModule" resultClass="hashMap"> select moduleId, actionId from StatMemberAction <dynamic prepend="where"> moduleId...
<select id="selectAllEmp" resultClass="hashmap"> SELECT * FROM EMP <!-- 按工号查询员工 --> <select id="selectEmpByNo" resultClass="com.microserver.pojo.Emp" parameterClass="string"> SELECT * ...
<select id="com.fashionfree.stat.accesslog.model.StatMemberAction.selectActionIdsOfModule" resultClass="hashMap"> select moduleId, actionId from StatMemberAction <dynamic prepend="where moduleId in">...
- **事务管理**:ibatis支持两种类型的事务管理机制,分别是基于JDBC的事务管理和基于JTA的事务管理。 - **基于JDBC的事务管理机制**:这是最简单的事务管理方式,适合于单数据源的情况。 - **基于JTA的事务管理...
<select id="getPeopleList" resultClass="model.User" parameterClass="java.util.Map"> <![CDATA[ select * from test where name like '%$name$%' ]]> ``` 在Java代码中,我们创建一个HashMap,并将参数放入...
<select id="getAddressByUserId" parameterClass="int" resultClass="address"> <![CDATA[ select address, zipcode from t_address where user_id=#userid# ]]> ``` 通过 `<result>` 标签,可以定义...
<select id="selectUser" parameterClass="java.lang.String" resultClass="User"> SELECT * FROM USERS WHERE NAME = #value# ``` **步骤3:编写DAO接口和实现** 定义一个`UserDao`接口,并使用Spring的`...