ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [ MVC02 / Mapper ] BoardMapper
    Spring 2022. 7. 22. 08:09

    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이랑 맵핑
    	// 메서드 이름 <--> xml의 id가 mapping이 된다.
    	public List<Board> boardList();
    	
    	// result type은 ==> return type 
    	// parameter type은 ==> 매개변수로 들어간다
    	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);
    	
    	public int boardUpdate2(Board vo);
    }

     

    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">
            delete from board
            where idx = #{idx}
        </delete>
        
        <update id="boardUpdate" parameterType="com.smhrd.domain.Board">
            update board set title=#{title}, writer=#{writer}, content=#{content} where idx=#{idx}
        </update>
        
        <update id="boardCount">
            update board
            set count = count + 1
            where idx = #{idx}
        </update>
        
        <update id ="boardUpdate2" parameterType="com.smhrd.domain.Board">
            update board
            set content=#{content}
            where idx = #{idx}
        </update>
    </mapper>

    'Spring' 카테고리의 다른 글

    [ MVC02 / Controller ] BoardController.java  (0) 2022.07.22
    [ MVC02 / Domain ] SQL.sql  (0) 2022.07.22
    [ MVC02 / Domain ] BoardVO.java  (0) 2022.07.22
    [ MVC02 / JS ] Board.js  (0) 2022.07.22
    [ MVC02 / View ] Base.jsp  (0) 2022.07.22

    댓글

Designed by Tistory.