for example, I have queries select id, name, age, address from staffs, instead of having a list of Staff object. I'd prefer to have a list of maps, as
list{
map{
("id", 123),
("name","jackie"),
("address", "canada"),
("age",26)
}
map{
("id", 126),
("name","james"),
("address", "canada"),
("age",27)
}
}
Run Code Online (Sandbox Code Playgroud)
is that possible, and how to do that, if possible? Thanks.
对的,这是可能的.您可以设置resultType为Hashmap你的XML映射文件,它会返回地图的列表.
<select id="selectFromStaffs" resultType="Hashmap">
select id, name, age, address from staffs
</select>
Run Code Online (Sandbox Code Playgroud)
而你得到它同样的方式:
...
List listOfMaps = sqlSession.selectList("selectFromStaffs");
...
Run Code Online (Sandbox Code Playgroud)
您可以在" 用户指南"中阅读有关它的更多信息.
在映射器 xml 类型resultType为"map"or "Hashmap",映射器接口中,您必须将 reutrn 类型写为"List":
StaffMapper.xml
<select id="getStaffList" resultType="map">
select id, name, age, address from staffs
</select>
Run Code Online (Sandbox Code Playgroud)
StaffMapper.java
<select id="getStaffList" resultType="map">
select id, name, age, address from staffs
</select>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8904 次 |
| 最近记录: |