在实际应用中我们经常会遇到这样的情况,需要给下拉框赋值,这个时候就需要键值对了,具体使用方法如下
1,在maper.xml文件中定义结果类型(resultType)定义为hashmap,如下所示
代码如下 | 复制代码 |
SELECT unit_id ,unit_name from unit_info
|
2,在对应的mapper类中用List
代码如下 | 复制代码 |
publicList |
其实最强大的莫过于resultMap类型了,这个可以在mapper.xml文件中自定义扩展类型,然后在包中添加这个类型即可,真是强大
下面给大家补充下MyBatis返回Map键值对数据
代码如下 | 复制代码 |
List select code,`name` from jk_control_measure [DEBUG]2016-08-2917:50:09:==> Executing: select code,`name` from jk_control_measure [DEBUG]2016-08-2917:50:09:==> Parameters: [DEBUG]2016-08-2917:50:10:<== Columns: code, name [DEBUG]2016-08-2917:50:10:<== Row: one, 地面冲洗 [DEBUG]2016-08-2917:50:10:<== Row: two, 边界围挡 [DEBUG]2016-08-2917:50:10:<== Row: three, 垃圾覆盖 [DEBUG]2016-08-2917:50:10:<== Row: four, 裸地覆盖 [DEBUG]2016-08-2917:50:10:<== Row: five, 洒水降尘 [DEBUG]2016-08-2917:50:10:<== Row: six, 车辆冲洗 [DEBUG]2016-08-2917:50:10:<== Row: seven, 建筑渣土 [DEBUG]2016-08-2917:50:10:<== Row: eight, 车辆冒装 [DEBUG]2016-08-2917:50:10:<== Row: nine, 扬尘覆盖 [DEBUG]2016-08-2917:50:10:<== Row: ten, 车辆撒漏 [DEBUG]2016-08-2917:50:10:<== Row: eleven, 车辆黑烟 [DEBUG]2016-08-2917:50:10:<== Row: twelve, 道路积尘 [{"NAME":"地面冲洗","name":"地面冲洗","code":"one","CODE":"one"}, {"NAME":"边界围挡","name":"边界围挡","code":"two","CODE":"two"}, {"NAME":"垃圾覆盖","name":"垃圾覆盖","code":"three","CODE":"three"}, {"NAME":"裸地覆盖","name":"裸地覆盖","code":"four","CODE":"four"}, {"NAME":"洒水降尘","name":"洒水降尘","code":"five","CODE":"five"}, {"NAME":"车辆冲洗","name":"车辆冲洗","code":"six","CODE":"six"}, {"NAME":"建筑渣土","name":"建筑渣土","code":"seven","CODE":"seven"}, {"NAME":"车辆冒装","name":"车辆冒装","code":"eight","CODE":"eight"}, {"NAME":"扬尘覆盖","name":"扬尘覆盖","code":"nine","CODE":"nine"}, {"NAME":"车辆撒漏","name":"车辆撒漏","code":"ten","CODE":"ten"}, {"NAME":"车辆黑烟","name":"车辆黑烟","code":"eleven","CODE":"eleven"}, {"NAME":"道路积尘","name":"道路积尘","code":"twelve","CODE":"twelve"} ] |
返回的结果带有大写与小写的key
创造与魔法 安卓版v1.0.0750
创造与魔法是一款开放世界手游,在游戏中玩家可探索这个奇妙的世
创造与魔法修改版 最新版v1.0.0750
创造与魔法无限点券版是款探索冒险游戏,该款游戏的操作还是蛮自
战争与文明官方版本 安卓版v1.7.16
战争与文明是一款由上海邮通科技有限公司开发的战争策略游戏,这
迷你世界0元领皮肤无限迷你币版 最新安卓版v1.43.0
迷你世界0元购买皮肤版是这款开放沙盒冒险建造游戏的特殊破解版
创造与魔法无限经验版 安卓版v1.0.0750
创造与魔法无限经验版是款可以改造环境,整个游戏的自由度还是蛮