Created
April 1, 2018 13:19
-
-
Save rararamorio/9f0d770fab656fec5647ac161b62c5af to your computer and use it in GitHub Desktop.
autoMapping を 有効にした場合のデータの取得方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<!DOCTYPE mapper | |
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
<mapper namespace="person"> | |
<resultMap id="personMap" autoMapping="true" type="jp.sample.mybatis.entity.Person"> | |
<id property="personId" column="person_id" /> | |
<collection property="books" columnPrefix="b_" resultMap="BookMap" /> | |
</resultMap> | |
<resultMap id="BookMap" autoMapping="true" type="jp.sample.mybatis.entity.Book"> | |
<id property="bookId" column="book_id" /> | |
<association property="category" columnPrefix="c_" resultMap="CategoryMap" /> | |
</resultMap> | |
<resultMap id="CategoryMap" autoMapping="true" type="jp.sample.mybatis.entity.Category"> | |
<id property="categoryId" column="category_id" /> | |
</resultMap> | |
<select id="selectByPersonId" resultMap="personMap"> | |
SELECT | |
p.person_id | |
, p.name | |
, b.book_id as b_book_id | |
, b.name as b_name | |
, c.category_id as b_c_category_id | |
, c.name as b_c_name | |
FROM | |
person p | |
INNER JOIN person_book pb USING(person_id) | |
INNER JOIN book b USING(book_id) | |
INNER JOIN category c USING(category_id) | |
WHERE | |
p.person_id=#{person_id} | |
</select> | |
</mapper> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment