Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.egovframe.rte.psl.dataaccess.mapper.EgovMapper;

import egovframework.example.sample.service.SampleVO;
Expand Down Expand Up @@ -45,6 +51,7 @@ public interface SampleMapper {
* @return 등록 결과
* @exception Exception
*/
@Insert("INSERT INTO SAMPLE ( ID, NAME, DESCRIPTION, USE_YN, REG_USER ) VALUES ( #{id}, #{name}, #{description}, #{useYn}, #{regUser} )")
void insertSample(SampleVO vo) throws Exception;

/**
Expand All @@ -53,6 +60,7 @@ public interface SampleMapper {
* @return void형
* @exception Exception
*/
@Update("UPDATE SAMPLE SET ID=#{id}, NAME=#{name}, DESCRIPTION=#{description}, USE_YN=#{useYn} WHERE ID=#{id}")
void updateSample(SampleVO vo) throws Exception;

/**
Expand All @@ -61,6 +69,7 @@ public interface SampleMapper {
* @return void형
* @exception Exception
*/
@Delete("DELETE FROM SAMPLE WHERE ID=#{id}")
void deleteSample(SampleVO vo) throws Exception;

/**
Expand All @@ -69,6 +78,14 @@ public interface SampleMapper {
* @return 조회한 글
* @exception Exception
*/
@Select("SELECT ID, NAME, DESCRIPTION, USE_YN, REG_USER FROM SAMPLE WHERE ID=#{id}")
@Results(id = "sampleResult", value = {
@Result(property = "id", column = "id", id = true),
@Result(property = "name", column = "name"),
@Result(property = "description", column = "description"),
@Result(property = "useYn", column = "use_yn"),
@Result(property = "regUser", column = "reg_user")
})
SampleVO selectSample(SampleVO vo) throws Exception;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,32 @@
<?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="egovframework.example.sample.service.impl.SampleMapper">
<mapper namespace="egovframework.example.sample.service.impl.SampleMapper">

<resultMap id="sample" type="egovframework.example.sample.service.SampleVO">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="description" column="description"/>
<result property="useYn" column="use_yn"/>
<result property="regUser" column="reg_user"/>
</resultMap>

<insert id="insertSample" parameterType="SampleVO">

INSERT INTO SAMPLE
( ID
, NAME
, DESCRIPTION
, USE_YN
, REG_USER )
VALUES ( #{id}
, #{name}
, #{description}
, #{useYn}
, #{regUser} )
<select id="selectSampleList" parameterType="searchVO" resultType="egovMap">

</insert>

<update id="updateSample">

UPDATE SAMPLE
SET ID=#{id}
, NAME=#{name}
, DESCRIPTION=#{description}
, USE_YN=#{useYn}
WHERE ID=#{id}

</update>

<delete id="deleteSample">

DELETE FROM SAMPLE
WHERE ID=#{id}

</delete>

<select id="selectSample" resultMap="sample">

SELECT
ID, NAME, DESCRIPTION, USE_YN, REG_USER
FROM SAMPLE
WHERE ID=#{id}

</select>

<select id="selectSampleList" parameterType="searchVO" resultType="egovMap">

SELECT
ID, NAME, DESCRIPTION, USE_YN, REG_USER
FROM SAMPLE
SELECT
ID, NAME, DESCRIPTION, USE_YN, REG_USER
FROM SAMPLE
WHERE 1=1
<if test="searchKeyword != null and searchKeyword != ''">
<choose>
<when test="searchCondition == 0">
AND ID LIKE '%' || #{searchKeyword} || '%'
<when test="searchCondition == 0">
AND ID LIKE '%' || #{searchKeyword} || '%'
</when>
<when test="searchCondition == 1">
AND NAME LIKE '%' || #{searchKeyword} || '%'
</when>
</choose>
</if>
ORDER BY ID DESC
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
</select>
<select id="selectSampleListTotCnt" parameterType="searchVO" resultType="int">
SELECT COUNT(*) totcnt
FROM SAMPLE
WHERE 1=1
ORDER BY ID DESC
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
</select>

<select id="selectSampleListTotCnt" parameterType="searchVO" resultType="int">

SELECT COUNT(*) totcnt
FROM SAMPLE
WHERE 1=1
<if test="searchKeyword != null and searchKeyword != ''">
<choose>
<when test="searchCondition == 0">
Expand All @@ -87,7 +36,7 @@
AND NAME LIKE '%' || #{searchKeyword} || '%'
</when>
</choose>
</if>
</select>
</if>
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void test() throws Exception {
// when
mockMvc.perform(

post("/sample/add")
post("/addSample.do")

.param("name", sampleVO.getName())

Expand Down