수정하기전, VO클래스에 list타입을 추가해준다
SqlMapConfig.xml
<typeAliases>
<typeAlias type="com.gorakgarak.entity.Director" alias="Director"></typeAlias>
<typeAlias type="com.gorakgarak.entity.Movie" alias="Movie"></typeAlias>
</typeAliases>
Director.xml
<?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="Director">
<!-- parameterMap은 안됨..3버전부터 -->
<insert id="insertDirector" parameterType="Director">
INSERT INTO director VALUES(#{id},#{name},#{age},#{winnerCount},#{profile}) <!-- 컬럼명아님 -->
</insert>
<update id="updateDirector" parameterType="Director">
UPDATE director SET director_age=#{age}, director_winnercount=#{winnerCount} where director_id=#{id}
</update>
<delete id="deleteDirector" parameterType="String">
DELETE FROM director WHERE director_id=#{value}
</delete>
<select id="selectAllDirector" resultType="Director">
select director_id as id,
director_name as name,
director_age as age,
director_winnercount as winnerCount from DIRECTOR
</select>
<resultMap type="Director" id="DirectorResultMap">
<id column="director_id" property="id"></id> <!-- property는 VO의 프로퍼티명, 대소문자 중요 -->
<result column="director_name" property="name"></result>
<result column="director_age" property="age"></result>
<result column="director_winnercount" property="winnerCount"></result>
</resultMap>
<select id="selectDirectorById" parameterType="String" resultMap="DirectorResultMap">
select director_id,
director_name,
director_age,
director_winnercount
from DIRECTOR
where director_id=#{value}
</select>
<select id="selectDirectorAge" parameterType="String" resultType="int">
select director_age from director where director_id = #{value}
</select>
<resultMap type="Movie" id="MovieResultMap" >
<id column="movie_id" property="id"/>
<result column="movie_title" property="title"/>
<result column="movie_year" property="year"/>
</resultMap>
<resultMap type="Director" id="DirectorJoinResultMap" extends="DirectorResultMap">
<collection property="movieList"
resultMap="MovieResultMap"></collection>
</resultMap>
<select id="selectDirectorWithMovieList" parameterType="String" resultMap="DirectorJoinResultMap">
select d.director_id,
d.director_name as,
d.director_age as,
d.director_winnercount, <!-- 대문자 주의한다. 별칭.. -->
m.movie_id,
m.movie_title,
m.movie_year
from director d, movie m
where d.director_id = m.director_id(+)
and d.director_id = #{value} <!-- 사실 다른이름 줘도 상관없음..어차피 하나가 오기 때문에 -->
</select>
</mapper>
'웹 & 프레임워크' 카테고리의 다른 글
마이바티스 에러 (0) | 2014.05.13 |
---|---|
<비공개> 동적쿼리 (0) | 2014.05.13 |
<비공개> DTD (0) | 2014.05.13 |
컨트롤러를 이용한 index.jsp 화면 설계 (0) | 2014.05.12 |
[서블릿] 필터 (Filter) (0) | 2014.05.12 |