728x90
반응형
mytabis ~.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="board">
<insert id="add" parameterType="net.hb.crud.BoardDTO">
insert into hobby
values(hobby_seq.nextVal, #{name}, #{title}, #{content}, #{gender}, #{hobby}, #{img_file_name} )
</insert>
<select id="selectAll" resultType="net.hb.crud.BoardDTO">
select rownum rn, h.* from hobby h
</select>
<select id="countAll" resultType="int">
select count(*) from hobby
</select>
<select id="detail" parameterType="int" resultType="net.hb.crud.BoardDTO">
select * from hobby where hobby_idx = #{data}
</select>
<delete id="del" parameterType="int">
delete from hobby where hobby_idx = #{data}
</delete>
<!-- 검색및 페이징 동적쿼리문 -->
<select id="countAllSearch" parameterType="net.hb.crud.BoardDTO" resultType="int" >
select count(*) from hobby where ${skey} like '%' || #{sval} || '%'
</select>
<select id="selectAll789" parameterType="net.hb.crud.BoardDTO" resultType="net.hb.crud.BoardDTO">
select * from (
select rownum rn, h.* ,(select count(*) from hobby_reply r where r.hobby_idx=h.hobby_idx) as rcnt from
(select * from hobby where ${skey} like '%' || #{sval} || '%' ) h
) where rn between #{start} and #{end}
</select>
<!-- selectAllTis -->
<select id="selectAllTis" parameterType="net.hb.crud.BoardDTO" resultType="net.hb.crud.BoardDTO">
select * from (
select rownum rn, h.* from hobby h
) where rn between #{start} and #{end}
</select>
<select id="selectAllDynamic" resultType="net.hb.crud.BoardDTO">
select * from (
select rownum as rn, h.* from (
select * from hobby
<if test="skey != null">
<if test="skey == 'name'">
where name like '%' || #{sval} || '%'
</if>
<if test="skey == 'title'">
where title like '%' || #{sval} || '%'
</if>
<if test="skey == 'content'">
where content like '%' || #{sval} || '%'
</if>
</if>
order by hobby_idx
) h
) where rn between #{start} and #{end}
</select>
</mapper>
SqlMapConfig.xml 문서에서 설정을 해주어야 한다.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="bdto" type="net.hb.crud.BoardDTO"/>
<typeAlias alias="gdto" type="net.hb.crud.GuestDTO"/>
</typeAliases>
<mappers>
<mapper resource="config/mybatis/guest.xml"/>
<mapper resource="config/mybatis/board.xml"/>
<mapper resource="config/mybatis/board_reply.xml"/>
<mapper resource="config/mybatis/login.xml"/>
</mappers>
</configuration>
728x90
반응형
'개발중 > Spring' 카테고리의 다른 글
AOP (0) | 2020.10.20 |
---|---|
pom.xml 문서 기록 (0) | 2020.10.20 |
db.properties (0) | 2020.10.20 |
Spring 을 다 고쳤을 때도 에러가 사라지지 않는다면 (0) | 2020.10.20 |
ModelAndView 문서의 흐름 (0) | 2020.10.20 |