Ibatis return Map type data

Source: Internet
Author: User

Sometimes do not want to create javabean, or pollute the existing JavaBean object, you need to return the map type of data objects;

1) The simplest method is to make the query to the field, using "" to cause, so that the map type can be returned;

2) or write Resultmap, to do the mapping of the field is also possible;


Examples are as follows:

1)

<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>


2)

<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>


Ibatis return Map type data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.