有时侯不想创建javabean,或者污染现有的javaBean对象,就需要返回Map类型的数据对象;

1)最简单的方法就是将查询到的字段,使用""进行引起来,这样就可以返回map类型了;

2)或者写成ResultMap,来进行字段的映射也是可以的;

例子如下:

  1. <select id="queryProductInfo" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
  2.   select a.marketproduct_code "productCode",
          a.marketproduct_name "productName",
  3.       a.product_class "productClass",
  4.       (select t.value_chinese_name from product_base_data t where t.collection_code = 'CPDL' and t.value_code = a.product_class) "productClassName",
          a.is_combined "isCombined",
  5.    a.combind_relation "packageType",
  6.    a.IS_SELF_CARD "isSelfCard",
  7.   (select decode(count(1), 0, '0', '1') from package_info t1 where t1.id_marketproduct_info = a.id_marketproduct_info) "hasPackage",
  8.    a.is_self_card "productKind",
  9.    a.marketproduct_type "productType",
  10.       b.least_copy_num "leastInusureAmout",
          b.top_copy_num "topInsureAmout",
  11.       b.insure_period_lmt_of_mon "periodSetMonth",
  12.       b.insure_period_lmt_of_day "periodSetDay",
  13.       b.least_accept_insure_age "leastAcceptInusrAge",
  14.       b.top_accept_insure_age "topAcceptInsurAge",
  15.       a.target_type "targetType",
  16.       b.PROFESSION_TYPE "professionType",
  17.       b.SPECIAL_PROMISE "specialPromise",
  18.       a.version "version"
        from marketproduct_info a,marketproduct_rule_param b, technic_product_info c where a.marketproduct_code = #marketproductCode#
  19.       and a.version = #version#
  20.       and a.id_marketproduct_info = b.id_marketproduct_info(+)
  21.       and a.id_technic_product_info = c.id_technic_product_info
  22. </select>
  1. <resultMap id="getItemsResult" class="java.util.HashMap">
  2.   <result property="itemName" column="item_name" />
  3.   <result property="itemValue" column="item_value" />
  4. </resultMap>
  5.  
  6. <select id="getItems" resultMap="getItemsResult">
  7. select item_name, item_value from item_table
  8. </select>

【ibatis】IBatis返回map类型数据的更多相关文章

  1. mybatis返回map类型数据空值字段不显示的解决方法

    在日常开发中,查询数据返回类型为map,数据库中有些自动值为null,则返回的结果中没有值为空的字段,则如何显示值为空的字段呢? Spring boot + MyBatis返回map中null值默认不 ...

  2. MyBatis探究-----返回Map类型数据

    1.使用@MapKey @MapKey:告诉mybatis封装Map的时候使用哪个属性作为Map的key Map<K, V>:键是这条记录的主键key,值是记录封装后的javaBean 1 ...

  3. mybatis返回map类型数据空值字段不显示(三种解决方法)

    转http://blog.csdn.net/lulidaitian/article/details/70941769 一.查询sql添加每个字段的判断空 IFNULL(rate,'') as rate ...

  4. Struts2+Jquery实现ajax并返回json类型数据

    来源于:http://my.oschina.net/simpleton/blog/139212 摘要 主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的 ...

  5. 转载:Struts2+Jquery实现ajax并返回json类型数据

    摘要: 主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的数据,并转换为json类型模式数据 3.配置struts.xml文件 4.页面脚本接受并处理数 ...

  6. Ajax返回xml类型数据

    ajax可以返回文本类型数据和xml类型数据,xml是计算机通用语言 可以使用js解析返回xml类型数据的dom对象 前端页面 <!doctype html> <html lang= ...

  7. Play Framework常用标签list,set,如何遍历list、map类型数据

    最近一段时间的项目都是在Play这个框架上进行开发的,挺强大的,但不足之处也挺多的.今天分享下play中强大的标签,遍历list,map类型的数据的用法. 遍历单纯的list数据,例如:List< ...

  8. [python] 查询mysql返回datetime类型数据的处理

    Python 查询Mysql,如果是datetime类型,在json序列化的时候会出现问题. 在网上查了一下,解决方案基本都是遍历dict数据,如果是datetime则转化为字符串. from dat ...

  9. Spring @ResponseBody只能返回String类型数据解决办法

    今天自己搭Spring MVC框架玩,使用AJAX调用Spring controller 并返回map对象,突然发现,哎,怎么@Response中只能返回String, 我用的Spring 3的版本也 ...

随机推荐

  1. Devexpress中Gridcontrol查找分组

    private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns. ...

  2. iis支持asp.net4.0的注册命令使用方法

    32位的Windows: 1. 运行->cmd 2. cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 3. aspnet_regiis.exe ...

  3. [初识]使用百度AI接口,图灵机器人实现简单语音对话

    一.准备 1.百度ai开放平台提供了优质的接口资源https://ai.baidu.com/  (基本免费) 2.在语音识别的接口中, 对中文来说, 讯飞的接口是很好的选择https://www.xf ...

  4. Linux正则与文本处理工具(10)

    正则表达式 (Regular Expression, RE, 或称为常规表达式)是通过一些特殊字符的排列,用于『查找/替换/删除』一行或多行文字或字符串,简单的说,正则表达式就是用在字串的处理上面的一 ...

  5. C语言判断进程是否存在

    #include <windows.h> #include <tlhelp32.h> //进程快照函数头文件 #include <stdio.h> bool get ...

  6. 序列化 pickle shelve json configparser

    模块pickle(皮考) dumps(当破死)序列化. 把对象转化成bytes loads(楼死) 反序列化. 吧bytes转化成对象 dic = {"jay": "周杰 ...

  7. Liferay开发实战(2):Service Builder生成持久化层,及开发服务层

    本文Liferay适用版本:v6.2.ce-ga6版 Liferay的插件体系是:模型-视图-控制器的portlet MVC框架.MVC是一个伟大的用于Web应用程序的设计模式,在实际应用中还应处理持 ...

  8. python学习笔记13-集合set

    set  集合 把不同的元素组合在一起  可以去除相同的元素  set(可哈希的) 无序不重复的.  取值:遍历取或者迭代取值 可哈希:不可变类型 set整体是非可哈希的. 即可变集合 不可变集合:f ...

  9. [EXP]WordPress Core 5.0 - Remote Code Execution

    var wpnonce = ''; var ajaxnonce = ''; var wp_attached_file = ''; var imgurl = ''; var postajaxdata = ...

  10. android(java) 开发过程中经验及总结记录

    android(java) 开发过程中经验及总结记录