IBatis multi-Table query, iBatis
<typeAlias alias="Product" type="com.shopping.entity.Product"/> <typeAlias alias="ProductType" type="com.shopping.entity.ProductType"/> <resultMap id="queryAllProduct" class="Product"> <result property="proId" column="proid"/> <result property="proName" column="proname"/> <result property="proDesc" column="prodesc"/> <result property="price" column="price"/> <result property="img" column="img"/> <result property="proTime" column="protime"/> <result property="size" column="size"/> <result property="type" column="typeid" select="queryProductTypeById"/> </resultMap> <select id="queryProductTypeById" parameterClass="int" resultClass="ProductType" > select typeid,typename from producttype where typeid=#typeid#<select><select id="queryAllProducts" resultMap="queryAllProduct"> select proid,proname,prodesc,price,img,protime,size,typeid from product<select>
Ibatis multi-Table query
I am also studying. I am developed in java, but the principle is the same. Let me talk about what I did!
Write A private List <Grade> grades; field in Table A in the Entity class.
Then modify the file xxxx. namingsql. xml.
<Result property = "grades" column = "id" select = "getGradeByUserId"/>
"GetGradeByUserId" is the ID of the query statement to be written to query all the two-dimensional tables.
<Select id = "getGradeByUserId" parameterClass = "int" resultClass = "orders table">
<! [CDATA [
Select student ID, course name, course score from B where student ID = # value #
]>
</Select>
This queries all the information in.
<Select id = "getUserList" resultMap = "result">
Select student ID, Student name, and gender from
</Select>
When you write a method and call getUserList, The getGradeByUserId method is automatically called to populate data in B with grades.
IBATIS multi-Table query
ResultMap = "java. util. HashMap"
Write SQL as follows:
Select sum (odd_price) sumoddprice, odr_customer_id custid
From sal_order join orders_line
On odd_order_id = odr_id
Group by odd_order_id
Then use hashMap. Get *** Value