MyBatis - accidentlywoo/secsec GitHub Wiki

ํ…Œ์ด๋ธ” ๋ช…๊ณผ vo ํด๋ž˜์Šค์˜ ํ•„๋“œ๋ช…์ด ์ผ์น˜ํ•  ๋•Œ ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค๊ฐ€ ๋ฆฌํ”Œ๋ ‰์…˜์œผ๋กœ setter ์ฃผ์ž…์„ ํ•œ๋‹ค.

๋ณต์žกํ•œ ๊ฒฐ๊ณผ๋งคํ•‘

๋งˆ์ด๋ฐ”ํ‹ฐ์Šค ๋ณต์žกํ•œ ๊ฒฐ๊ณผ ๋งคํ•‘

<!-- Very Complex Result Map -->
<resultMap id="detailedBlogResultMap" type="Blog">
  <constructor>
    <idArg column="blog_id" javaType="int"/>
  </constructor>
  <result property="title" column="blog_title"/>
  <association property="author" javaType="Author">
    <id property="id" column="author_id"/>
    <result property="username" column="author_username"/>
    <result property="password" column="author_password"/>
    <result property="email" column="author_email"/>
    <result property="bio" column="author_bio"/>
    <result property="favouriteSection" column="author_favourite_section"/>
  </association>
  <collection property="posts" ofType="Post">
    <id property="id" column="post_id"/>
    <result property="subject" column="post_subject"/>
    <association property="author" javaType="Author"/>
    <collection property="comments" ofType="Comment">
      <id property="id" column="comment_id"/>
    </collection>
    <collection property="tags" ofType="Tag" >
      <id property="id" column="tag_id"/>
    </collection>
    <discriminator javaType="int" column="draft">
      <case value="1" resultType="DraftPost"/>
    </discriminator>
  </collection>
</resultMap>

Many To One๊ด€๊ณ„์—์„œ [Blog์™€ Author]

-> One : property -> VO ์ปฌ๋Ÿผ๋ช…

-> Many

One To Many๊ด€๊ณ„์—์„œ[Blog์™€ Post]

id ๊ฐ’ ์„ค์ •

id ๊ฐ’ ์„ค์ •์„ ํ•˜์ง€ ์•Š์œผ๋ฉด select ๊ฒฐ๊ณผ๊ฐ€ ์ฟผ๋ฆฌ๋ฌธ ๊ฒฐ๊ณผ์™€ ๋™์ผํ•˜๊ฒŒ ์ถœ๋ ฅ๋œ๋‹ค. ํ•˜์ง€๋งŒ, ๊ฐ์ฒด์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” id๊ฐ’์„ ์ง€์ •ํ•ด์„œ ๋ถˆํ•„์š”ํ•œ ๊ฐ์ฒด์ƒ์„ฑ์„ ๋ง‰๋Š”๋‹ค.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ