Associated with the query:
One:
1, class business expansion
Core: resultType with the specified class of property contains all the fields in multi-table queries.
2、resultMap
To establish a connection between the two members of the class by adding attributes
<! - use resultMap achieve one ->
<select id="queryPersonsByReOnetoOne" parameterType="int" resultMap="person-card-map">
select p.*,c.* from person p inner join personcard c
on p.cardid = c.cardid
where p.id=#{id}
</select>
<-! ResultMap implement the mapping ->
<resultMap type="person" id="person-card-map">
<-! Person Information ->
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<! - one on one, the members of the object using the assocation achieve mapping, javaType specify the type of the property ->
<
association property="card" javaType="PersonCard">
<id property="cardid" column="cardid"/>
<result property="cardinfo" column="cardinfo"/>
</association>
</resultMap>
Many:
<! -
many associated with the query
->
<select id="queryClassAndPersons" parameterType="int" resultMap="class-person-map">
select c.*,p.* from person p
inner join class c
on c.classid=p.classid
where c.classid=#{classid}
</select>
<! - correspondence relationship between classes and tables ->
<resultMap type="class" id="class-person-map">
<! - first with class ->
<id property="classid" column="classid" />
<result property="classname" column="classname" />
<! - Configure member properties. Attribute Type: jdbcType; element type attributes: ofType ->
<
collection property="persons" ofType="Person">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</collection>
</resultMap>