Ibatis.net Series (eight)-parametric mapping

Source: Internet
Author: User

Parameter mapping refers to the ibatis of the object, or Ibatis to return the object when the property mapping relationship, mainly Parametermap (incoming parameter mapping), RESULTMAP (return parameter mapping).
Parametermap: Pass-through parameter mappings, which are mostly used in stored procedures and are later spoken.
Resultmap: Return parameter mappings when we need to return different objects, primarily mapping the results of our query to another object instead of having to reassemble new objects in the program.
Like we have a new object.
public class STU1
{
public int UserId {get; set;}
public string UserName {get; set;}
public string Usersex {get; set;}
}
Requires student query results to return this object
We can configure the SQL node like this:
<select id= "Selectstu" parameterclass= "int" resultmap= "Stu" >
SELECT * FROM student where id= #id #
</select>
where resultmap= "Stu" points to a mapping node called STU, which is configured as follows
<resultMaps>
<resultmap id= "Stu" class= "IBNETMODEL.STU1" >
<result column= "Id" property= "userid"/>
<result column= "Name" property= "UserName"/>
<result column= "Sex" property= "Usersex"/>
</resultMap>
</resultMaps>
Note that the Resultmaps node is parallel to the statements.
column represents the returned columns,
The property indicates that the return column is mapped to the properties of the Ibnetmodel.stu1 class.
So we can write that in the program.
Methods in the Student class
Public ilist<stu1> selectstu (int id)
{
Return mapper. Queryforlist<stu1> ("Selectstu", id);
}
Call:
ilist<stu1> list = new Student (). Selectstu (14);

Tips: When we selectstu this method, it calls the id= "selectstu" SQL statement, and the return result is mapped to Stu by the id= "ibnetmodel.stu1" Mapping file.

Ibatis.net Series (eight)-parametric mapping

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.