Ibatis one-to-Multiple Solution

Source: Internet
Author: User

Resultmap in the sqlmap file:

       <  Resultmap  ID  = "Productandpackageresult"  Class  = "Productandpackage"   >            <  Result  Column  = "ID"  Property  = "ID"  Jdbctype  = "Decimal"   />         <  Result  Column  = "Name"  Property  = "Name"  Jdbctype  = "Varchar"   />          <  Result  Column  = "Disctription"  Property  = "Disctription"  Jdbctype = "Varchar"   />          <  Result  Column  = "Duration"  Property  = "Duration"  Jdbctype  = "Decimal"   />          <  Result  Column  = "Status"  Property  = "Status" Jdbctype  = "Decimal"   />          <  Result  Column  = "Ad_count"  Property  = "Adcount"  Jdbctype  = "Decimal"   />          <  Result  Column  = "Begin_time" Property  = "Begintime"  Jdbctype  = "Date"   />          <  Result  Column  = "End_time"  Property  = "Endtime"  Jdbctype  = "Date"   />          <  Result  Column = "Market_price"  Property  = "Marketprice"  Jdbctype  = "Decimal"   />          <  Result  Column  = "Price"  Property  = "Price"  Jdbctype  = "Decimal"   />          < Result  Column  = "Release_tel_num"  Property  = "Releasetelnum"  Jdbctype  = "Decimal"   />          <  Result  Column  = "Relevance_tel_num"  Property  = "Relevancetelnum"  Jdbctype  = "Decimal"  />           <  Result  Property  = "Productpackagelist"  Column  = "{Productid = ID, areaid = areaid, status = status }"  Select  = "Productpackagesql. getbyproductid"  />         </  Resultmap  > 

Note:ProductpackagelistThe field is.Select= "Productpackagesql. getbyproductid.

GetbyproductidThe SELECT statement of is as follows:

 

     <  Select  ID  = "Getbyproductid"  Resultmap  = "Productpackageresult"  Parameterclass  = "Java. util. hashmap"  > Select * From tb_product_package where product_id = # productid #  <  Isnotnull  Property  = "Areaid"  Prepend  = "And"  >  Area_id = # areaid #  </  Isnotnull  >              <  Isnotnull  Property = "Status"  Prepend  = "And"  >  Status = # status #  </  Isnotnull  >              </  Select  > 

 

 
ProductandpackageresultUsage:
     <  Select  ID = "Getlist"  Resultmap  = "Productandpackageresult"  Parameterclass  = "Java. util. Map"  >  Select ID, name, disctription, duration, status, price, ad_count, begin_time, end_time, market_price, price, release_tel_num, relevance_tel_num, # areaid # As areaid, # status # As status from tb_product  <  Dynamic  Prepend  = "Where"  >              < Isnotempty  Prepend  = "And"  Property  = "Productid"  >  Id = # productid #  </  Isnotempty  >          </  Dynamic  >  Order by ID  </  Select > 

 

It should be noted that this word query has three parameters. Generally, the relationship between the primary key and the foreign key is one-to-many. This solution is to solve this possible multi-parameter situation.

The key of the example is to use# Areaid # As areaid, # status # As status, which can be used in Word query.StatusAndAreaidThese two parameters.

 

 

 

 

 

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.