똑같은 삽질은 2번 하지 말자
Java(Enum) → DB(Int) 본문
<mapper namespace="com.board.mapper.BoardMapper">
<resultMap type="com.board.dto.BoardVO" id="board">
<result column="b_kind" property="b_kind" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
<result column="b_code" property="b_code"/>
<result column="b_title" property="b_title"/>
<result column="b_content" property="b_content"/>
<result column="b_indate" property="b_indate"/>
<result column="b_hit" property="b_hit"/>
<result column="b_like" property="b_like"/>
<result column="b_writer" property="b_writer"/>
</resultMap>
<select id="getAllBoardList" resultMap="board">
select * from board
</select>
<select id="getPagingBoardList" resultMap="board" parameterType="utils.CriteriaVO">
SELECT P.*
FROM (SELECT * FROM BOARD
WHERE B_TITLE LIKE CONCAT('%',#{searchKeyword},'%')
ORDER BY B_CODE ASC) AS P
LIMIT #{perPageNum} OFFSET #{pageStart}
</select>
<select id="getTotalRecord" resultType="Integer">
select count(*) from board
</select>
<insert id="save" parameterType="com.board.dto.BoardVO">
INSERT INTO BOARD(b_title,b_content,b_writer,b_kind)
VALUES(
#{b_title},
#{b_content},
#{b_writer},
#{b_kind, typeHandler = org.apache.ibatis.type.EnumOrdinalTypeHandler}
)
</insert>
<delete id="delete" parameterType="int">
DELETE FROM BOARD WHERE B_CODE = #{b_code}
</delete>
<select id="findOne" parameterType="int" resultMap="board">
SELECT * FROM BOARD WHERE B_CODE = #{b_code}
</select>
<update id="updateHit" parameterType = "int" >
UPDATE BOARD SET B_HIT = B_HIT + 1 WHERE B_CODE = #{b_code}
</update>
</mapper>
public enum BoardKind {
FreeBoard(1),
MemberBoard(2),
AdminBoard(3);
private final int kind;
BoardKind(int kind){
this.kind = kind;
}
public int getKind() {
return kind;
}
public static BoardKind valueOf(int kind) {
switch(kind) {
case 1:
return FreeBoard;
case 2:
return MemberBoard;
case 3:
return AdminBoard;
default :
throw new AssertionError("Unknown kind" + kind);
}
}
}
DBとJavaのIndexの番号が合わなくてエラーができました。
'Spring' 카테고리의 다른 글
Spring 로깅(Logging) (0) | 2020.11.14 |
---|---|
Lombok(롬복)은 어떻게 동작하는 걸까? (0) | 2020.09.19 |
Spring+JPA REST API 성능 최적화 (0) | 2020.06.13 |
@PathVariable 사용해보자(전달인자 처리) (0) | 2020.06.07 |
Redirect parameter ? How are you going to spend it? (0) | 2020.04.23 |
Comments