-
[ MVC01 / Mapper ] BoardMapperSpring 2022. 7. 22. 08:01
1. BoardMapper.java
package com.smhrd.mapper; import java.util.List; import com.smhrd.domain.Board; //DAO를 interface로 만든다 public interface BoardMapper { //연결된 xml파일이랑 이름이 같아야함 //DB 연결은 다른 파일에서 진행 //추상메서드 //Spring에서 쓸때는 추상메서드만 만들고, mapper.xml이랑 맵핑 public List<Board> boardList(); public int boardInsert(Board vo); public Board boardContent(int idx); public int boardDelete(int idx); public int boardUpdate(Board vo); public int boardCount(int idx); }
2. BoardMapper.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="com.smhrd.mapper.BoardMapper"> <select id="boardList" resultType="com.smhrd.domain.Board"> select * from board </select> <insert id="boardInsert" parameterType="com.smhrd.domain.Board"> insert into board(title,writer,content) values(#{title},#{writer},#{content}) </insert> <select id="boardContent" resultType="com.smhrd.domain.Board"> select * from board where idx=#{idx} </select> <delete id="boardDelete" parameterType="int"> delete from board where idx=#{idx} </delete> <update id="boardUpdate" parameterType="com.smhrd.domain.Board"> update board set content = #{content} where idx = #{idx} </update> <update id="boardCount"> update board set count = count+1 where idx = #{idx} </update> </mapper>
'Spring' 카테고리의 다른 글
[ MVC02 / View ] Base.jsp (0) 2022.07.22 [ MVC01 / Controller ] BoardController.java (0) 2022.07.22 [ MVC01 / Domain ] SQL.sql (0) 2022.07.22 [ MVC01 / Domain ] BoardVO.java (0) 2022.07.22 [ MVC01 / View ] BoardUpdate.jsp (0) 2022.07.22