今天遇到一个问题:
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>
|