IBatis返回map类型数据

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

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

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

例子如下:

<select id="queryProductInfo"  parameterClass="java.util.HashMap"   resultClass="java.util.HashMap">
  select a.marketproduct_code "productCode",      a.marketproduct_name "productName",
      a.product_class "productClass",
      (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",
         a.combind_relation "packageType",
         a.IS_SELF_CARD "isSelfCard",
         (select decode(count(1), 0, ‘0‘, ‘1‘) from package_info t1 where t1.id_marketproduct_info = a.id_marketproduct_info) "hasPackage",
         a.is_self_card "productKind",
         a.marketproduct_type "productType",
      b.least_copy_num "leastInusureAmout",      b.top_copy_num "topInsureAmout",
      b.insure_period_lmt_of_mon "periodSetMonth",
      b.insure_period_lmt_of_day "periodSetDay",
      b.least_accept_insure_age "leastAcceptInusrAge",
      b.top_accept_insure_age "topAcceptInsurAge",
      a.target_type "targetType",
      b.PROFESSION_TYPE "professionType",
      b.SPECIAL_PROMISE "specialPromise",
      a.version "version"      from marketproduct_info a,marketproduct_rule_param b, technic_product_info c where a.marketproduct_code = #marketproductCode#
      and a.version = #version#
      and a.id_marketproduct_info = b.id_marketproduct_info(+)
      and a.id_technic_product_info = c.id_technic_product_info
</select>
<resultMap id="getItemsResult" class="java.util.HashMap">
  <result property="itemName" column="item_name" />
  <result property="itemValue" column="item_value" />
</resultMap>

<select id="getItems" resultMap="getItemsResult">
      select item_name, item_value from item_table
</select>
时间: 2024-08-28 07:35:19

IBatis返回map类型数据的相关文章

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

在日常开发中,查询数据返回类型为map,数据库中有些自动值为null,则返回的结果中没有值为空的字段,则如何显示值为空的字段呢? Spring boot + MyBatis返回map中null值默认不显示,如要调整为null值显示需要在配置文件中添加属性,如下图红框中所示: 2.Mybatis使用IFNULL(P1,P2)函数 原文地址:https://www.cnblogs.com/panchanggui/p/10919421.html

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

主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的数据,并转换为json类型模式数据 3.配置struts.xml文件 4.页面脚本接受并处理数据 网上看到很多关于Struts2+ajax+jquery+json的例子,但是很多都不完整,也看不明白,主要原因是返回jsno类型数据和原来的返回字符串类型数据不一样,并且网友们实现步骤没有说清楚,让初学的朋友捉摸不透到底该怎么做. 我做了个简单的demo,供网友们学习,最后我会附上链接,可以下载整个de

Ajax返回xml类型数据

ajax可以返回文本类型数据和xml类型数据,xml是计算机通用语言 可以使用js解析返回xml类型数据的dom对象 前端页面 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name=

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

今天自己搭Spring MVC框架玩,使用AJAX调用Spring controller 并返回map对象,突然发现,哎,怎么@Response中只能返回String, 我用的Spring 3的版本也不低啊,百思不得其解,遂去官方论坛查找原因,好家伙,好多人都有这个经历,而且貌似有些官方人员也说不清怎么解决,人家提问题的都嚷嚷着要去提交bug了(看来官方支持人员也有渣渣啊).于是去spring-vramework官网查看文档,有如下描述Jackson  is supported directly

mybatis group by查询返回map类型

故事的发生是这样的. . . . . . . 一天 我发现我们的页面显示了这样的汇总统计数据,看起来体验还不错哦-- 然后,我发现代码是这样滴:分开每个状态分别去查询数量. 额e,可是为嘛不使用简单便捷的 group by 语句呢 我们知道MyBatis提供了selectMap的方法,查询结果为hashmap.查询的时候,可以配置相应的传入参数和查询返回结果. 对应dao 层代码如下: //查询各状态对应的数量,三个参数分别对应,select的id,查询参数,返回hashmap的key publ

ibatis返回map列表

1. resultClass="java.util.HashMap"   <select id="queryCustmerCarNoByCustId" resultClass="java.util.HashMap" parameterClass="string"> select t.vehicle_no from NETS2_T_PC_VEHICLE t where t.nets_cust_id=#custId#

查询List&lt;Map&gt;类型数据

只要设定resultType而不设定resultMap就可以了. Java接口: List<Map<String, String>> getMtypeList(); XML: <select id="getMtypeList" parameterType="java.util.Map" resultType="java.util.HashMap"> select code,`name` from jk_cont

MyBatis查询结果resultType返回值类型详细介绍

一.返回一般数据类型比如要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值 String getEmpNameById(Integer id); SQL 映射文件: <!-- 指定 resultType 返回值类型时 String 类型的, string 在这里是一个别名,代表的是 java.lang.String 对于引用数据类型,都是将大写字母转小写,比如 HashMap 对应的别名是 'hashmap' 基本数据

SpringMVC 目标方法返回 json 格式数据

第一种方法:使用  @ResponseBody 注解来实现 1.Spring MVC 配置 <mvc:annotation-driven></mvc:annotation-driven>.添加该配置的作用如下,而我们用到的是... 2.添加 jackson-annotations-2.1.5.jar.jackson-core-2.1.5.jar.jackson-databind-2.1.5.jar 三个注解. 3.在 handler 目标方法中返回集合类型数据并添加 @Respon