There are two ways to correlate nested queries and nested results, which are described in this way by nested results.
The previous chapter introduced the relationship of many to one and used <association></association> This is a complex type of association. We select an example to review, such as: a blog has a user, the correlation map works on this result. First look at the table structure fields we'll use in this article:
[SQL] view plain Copy blog Blog:id title author_id author author:id username password email Bio fa Vourite_section article Post:id blog_id author_id created_on section subject draft body comment Comment:id post_id name Comment Label T:id name we associate a blog with a user, like this:
[SQL] View plain copy <select id= "selectblog" parametertype= "int" resultmap= "BlogResult" > select b.id as blog_id, b.title as blog_title, b.author_id as blog_author_id a.id as author_id, a.username as author_username, a.password as author_passowrd, a.email as auhtor_email, a.bio as author_bio from blog b left outer join author a on b.author_id=a.id where b.id=#{id} </select>
Note that this federated query, and all results are renamed with a unique and clear name. This makes the mapping very simple. Now we can map this result:
[SQL] view plain copy <resultmap id= "Blogresult" type= "Blog" > <id property= "id" column= "blog_id "/> <result property=" title "column=" Blog_title "/> <!--and a user association, the blog class inside the attribute when author, the associated Column is the original blog.author_id--> <association property= "author" column= "blog_author_id" javatype= "Author" resultmap= "Authorresult"/> </resultMap>