我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

Mybatis结果生成键值对的实例代码

下面给大家介绍下mybatis结果生成键值对的实例代码,具体内容如下所示:

10多年的站前网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网整合营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整站前建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“站前网站设计”,“站前网站推广”以来,每个客户项目都认真落实执行。

在实际应用中我们经常会遇到这样的情况,需要给下拉框赋值,这个时候就需要键值对了,具体使用方法如下

1,在maper.xml文件中定义结果类型(resultType)定义为hashmap,如下所示

2,在对应的mapper类中用List>来接受这个类型,如下所示

public List> selectSuperUnitInfo();

其实最强大的莫过于resultMap类型了,这个可以在mapper.xml文件中自定义扩展类型,然后在包中添加这个类型即可,真是强大

下面给大家补充下MyBatis返回Map键值对数据

List> getMtypeList();
[DEBUG] 2016-08-29 17:50:09 :==> Executing: select code,`name` from jk_control_measure 
[DEBUG] 2016-08-29 17:50:09 :==> Parameters: 
[DEBUG] 2016-08-29 17:50:10 :<==  Columns: code, name
[DEBUG] 2016-08-29 17:50:10 :<==    Row: one, 地面冲洗
[DEBUG] 2016-08-29 17:50:10 :<==    Row: two, 边界围挡
[DEBUG] 2016-08-29 17:50:10 :<==    Row: three, 垃圾覆盖
[DEBUG] 2016-08-29 17:50:10 :<==    Row: four, 裸地覆盖
[DEBUG] 2016-08-29 17:50:10 :<==    Row: five, 洒水降尘
[DEBUG] 2016-08-29 17:50:10 :<==    Row: six, 车辆冲洗
[DEBUG] 2016-08-29 17:50:10 :<==    Row: seven, 建筑渣土
[DEBUG] 2016-08-29 17:50:10 :<==    Row: eight, 车辆冒装
[DEBUG] 2016-08-29 17:50:10 :<==    Row: nine, 扬尘覆盖
[DEBUG] 2016-08-29 17:50:10 :<==    Row: ten, 车辆撒漏
[DEBUG] 2016-08-29 17:50:10 :<==    Row: eleven, 车辆黑烟
[DEBUG] 2016-08-29 17: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

如果在sql语句中的列名使用大写会怎样呢?自己测试一下吧!如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对创新互联网站的支持!


新闻标题:Mybatis结果生成键值对的实例代码
链接URL:http://shouzuofang.com/article/jheedj.html

其他资讯