-
day58 - MyBatis(parameterType, resultType, 게시판에 mybatis 적용)KIC/MyBatis 2021. 9. 6. 23:46반응형
[board.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" > <select id="seqNextval" resultType="int"> select multiboardseq.nextval from dual </select> <insert id="insertBoard" parameterType="board"> insert into multiboard (num, name, pass, subject, content, file1, regdate, readcnt, ref,reflevel, refstep, boardid) values (# {num}, #{name}, #{pass},#{subject},#{content}, #{file1}, sysdate, 0,#{ref}, #{reflevel},#{refstep},#{boardid}) </insert> <!-- 파라미터가 boardid 하나만 있으므로 parameterType은 String, 결과 값은 count 값이므로 int--> <select id="boardCount" parameterType="String" resultType="int"> select count(*) count from multiboard where boardid=#{boardid} </select> <!-- 파라미터가 여러개이니 map으로, 결과 값은 * 로 여러개를 묶어 출력하니 board 로 --> <select id="list" parameterType="map" resultType="board"> select * from (select rownum rnum,a.* from (select * from multiboard where boardid = #{boardid} order by ref desc, refstep) a ) where rnum between #{start} and #{end} </select> <!-- select는 결과값이 select문을 통해 출력되기 때문에 parameterType 뿐만 아니라 resultType도 있어야 한다. --> <select id="selectOne" parameterType="int" resultType="board"> select * from multiboard where num=#{num} </select> <select id="readcntadd" parameterType="int"> update multiboard set readcnt = readcnt + 1 where num =#{num} </select> <update id="refstepadd" parameterType="map"> update multiboard set refstep = refstep + 1" + " where ref = #{ref} and refstep > #{refstep} </update> <update id="update" parameterType="board"> update multiboard set name=#{name},subject=#{subject},content=#{content},file1=#{file1}" + " where num=#{num} </update> <!-- insert, update, delete는 결과 값이 없기 때문에 resultType은 없고 parameterType은 있다. --> <delete id="delete" parameterType="int"> delete from multiboard where num=#{num} </delete> </mapper>
300x250'KIC > MyBatis' 카테고리의 다른 글
day59 - MyBatis(게시판 mybatis 적용) (0) 2021.09.07 day57 - MyBatis(parameterType, resultType) (0) 2021.09.03 day56 - MyBatis(Mybatis, Mybatis 실행 절차) (0) 2021.09.03 java.sql.SQLException: ORA-01017: invalid username/password; logon denied (0) 2021.09.03