반응형
1.boardDTO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | package com.example.web03.model.board.dto; import java.sql.Date; import org.springframework.web.multipart.MultipartFile; public class BoardDTO { private int idx; private String userid; private String username; // 멤버테이블의 이름 private String subject; private String content; private int hit; private String fileDel; private long filesize; private int down; private int ref; private int depth; private int reorder; private int comment_count; //첨부파일 저장하기 위한 값 private MultipartFile file1; public String getFileDel() { return fileDel; } public void setFileDel(String fileDel) { this.fileDel = fileDel; } private Date post_date; private String filename; public int getComment_count() { return comment_count; } public void setComment_count(int comment_count) { this.comment_count = comment_count; } public MultipartFile getFile1() { return file1; } public void setFile1(MultipartFile file1) { this.file1 = file1; } // 기본생성자 // 매개변수가 있는 생성자(userid, subject,content) // getter, setter // toString() public int getIdx() { return idx; } public void setIdx(int idx) { this.idx = idx; } public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public int getHit() { return hit; } public void setHit(int hit) { this.hit = hit; } public Date getPost_date() { return post_date; } public void setPost_date(Date post_date) { this.post_date = post_date; } public String getFilename() { return filename; } public void setFilename(String filename) { this.filename = filename; } public long getFilesize() { return filesize; } public void setFilesize(long filesize) { this.filesize = filesize; } public int getDown() { return down; } public void setDown(int down) { this.down = down; } public int getRef() { return ref; } public void setRef(int ref) { this.ref = ref; } public int getDepth() { return depth; } public void setDepth(int depth) { this.depth = depth; } public int getReorder() { return reorder; } public void setReorder(int reorder) { this.reorder = reorder; } @Override public String toString() { return "BoardDTO [idx=" + idx + ", userid=" + userid + ", username=" + username + ", subject=" + subject + ", content=" + content + ", hit=" + hit + ", post_date=" + post_date + ", filename=" + filename + ", filesize=" + filesize + ", down=" + down + ", ref=" + ref + ", depth=" + depth + ", reorder=" + reorder + "]"; } public BoardDTO(String userid, String username, String content) { super(); this.userid = userid; this.username = username; this.content = content; } public BoardDTO() { // TODO Auto-generated constructor stub } } | cs |
2.BOARDDAO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | package com.example.web03.model.board.dao; import java.util.List; import com.example.web03.model.board.dto.BoardDTO; public interface BoardDAO { //由ъ뒪�듃 public List<BoardDTO> boardList(int start,int end, String search_option, String search); } | cs |
3.DAOIMPL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | package com.example.web03.model.board.dao; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.inject.Inject; import org.apache.ibatis.session.SqlSession; import org.springframework.stereotype.Repository; import com.example.web03.model.board.dto.BoardDTO; @Repository public class BoardDAOImpl implements BoardDAO { @Inject SqlSession sqlSession; @Override public List<BoardDTO> boardList(int start, int end, String search_option, String search) { List<BoardDTO> list = null; try { Map<String, Object> map = new HashMap<String, Object>(); map.put("start", start); map.put("end", end); map.put("search_option", search_option); map.put("search", search); list = sqlSession.selectList("boardList", map); } catch (Exception e) { e.printStackTrace(); } return list; } } | cs |
SERVICE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | package com.example.web03.service.board; import java.util.List; import com.example.web03.model.board.dto.BoardDTO; import com.example.web03.model.board.dto.CommentDTO; public interface BoardService { public List<BoardDTO> boardList(int start, int end, String search_option, String search); } | cs |
SERVICEIMPL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | package com.example.web03.service.board; import java.io.File; import java.util.List; import javax.inject.Inject; import org.springframework.stereotype.Service; import com.example.web03.model.board.dao.BoardDAO; import com.example.web03.model.board.dao.CommentDAO; import com.example.web03.model.board.dto.BoardDTO; import com.example.web03.model.board.dto.CommentDTO; @Service // �쁽�옱 �겢�옒�뒪瑜� �뒪�봽留� �꽌鍮꾩뒪 鍮덉쑝濡� �벑濡앹떆�궡 public class BoardServiceImpl implements BoardService { @Inject BoardDAO boardDAO; // BoardDAOImpl �씤�뒪�꽩�뒪瑜� �깮�꽦�븯�뿬 二쇱엯�떆�궡 @Inject CommentDAO commentDao; @Override public List<BoardDTO> boardList(int start, int end,String search_option, String search) { List<BoardDTO> list; list = boardDAO.boardList(start, end,search_option,search); return list; } } | cs |
CONTROLLER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | public class BoardController { // 濡쒓굅 李띻린 蹂��닔 private static final Logger Logger = LoggerFactory.getLogger(BoardController.class); @Inject BoardService boardService; // BoardServiceImpl�쓣 二쇱엯�떆�궡 @RequestMapping("board/board_list.do") public String board_list(@RequestParam(defaultValue = "1") int curPage, Model model, @RequestParam(required = false, defaultValue = "username") String search_option, @RequestParam(required = false, defaultValue = "") String search) { /* * @RequestParam에 지정된 변수에 값이 넘어오지 않으면 400에러 발생 required=false 필수 입력항목이 * 아님, 기본값은 required=true defaultValue= "기본값" */ int count = boardService.boardCount(search_option, search); PageDAO pageDao = new PageDAO(count, curPage); int start = pageDao.getPageBegin(); int end = pageDao.getPageEnd(); List<BoardDTO> list = boardService.boardList(start, end, search_option, search); model.addAttribute("list", list); // 페이지 네비게이션 관련자료 저장 model.addAttribute("page", pageDao); // 검색관련 정보 저장 model.addAttribute("search_option", search_option); model.addAttribute("search", search); Logger.info("�럹�씠吏��젙蹂�:" + pageDao); return "board/board_list"; } | cs |
page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%-- <%@ page session="false"%> --%> <c:set var="path" value="${pageContext.request.contextPath}"></c:set> <jsp:include page="boardHeader.jsp" flush="false"/> <h1 id="community"><div>COMMUNITY</div></h1> <article> <h2>게시판</h2> <table border="1" align="center" class="tbl_type" WIDTH=50% table-layout: fixed> <tr> <th nowrap WIDTH="40">번호</th> <th nowrap WIDTH="100">이름</th> <th nowrap WIDTH="250">제목</th> <th nowrap WIDTH="100">날짜</th> <th nowrap WIDTH="40">조회</th> <th nowrap WIDTH="70">첨부파일</th> <th nowrap WIDTH="70">다운로드</th> </tr> <c:forEach var="row" items="${list}"> <tr> <td>${row.idx }</td> <td>${row.username }</td> <td> <!-- 답변 들여쓰기 --> <c:forEach begin="1" end="${row.depth }"> </c:forEach> <a href="${path}/board/view.do?idx=${row.idx}"> ${row.subject}</a> <c:if test="${row.comment_count >0 }"> <span style="color:red">[${row.comment_count}]</span> </c:if> </td> <td>${row.post_date}</td> <td>${row.hit}</td> <!-- 첨부파일의 사이즈가 0 보다 크면 파일 다운로드 링크 표시 --> <td align="center"> <c:if test="${row.filesize > 0 }"> <a href="${path}/board/down.do?idx=${row.idx}"> <img src="${path}/images/file.gif"> </a> </c:if> </td> <td>${row.down}</td> </tr> </c:forEach> <tr align="center"> <td colspan="7"> <!-- 이전 --> <c:if test="${page.curPage>1 }"> <a href="${path}/board/board_list.do?curPage=1&search_option=${search_option}&search=${search}">[시작] </a> </c:if> <c:if test="${page.curBlock > 1 }"> <a href="${path}/board/board_list.do?curPage=${page.prevPage}&search_option=${search_option}&search=${search}">[이전] </a> </c:if> <c:forEach var="pageNum" begin="${page.blockStart}" end="${page.blockEnd}"> <c:choose> <c:when test="${pageNum==page.curPage }"> <span style="color:red">[${pageNum}]</span> </c:when> <c:otherwise> <a href="${path}/board/board_list.do?curPage=${pageNum}&search_option=${search_option}&search=${search}">[${pageNum}] </a> </c:otherwise> </c:choose> </c:forEach> <!-- 다음 --> <c:if test="${page.curBlock <= page.totBlock}"> <a href="${path}/board/board_list.do?curPage=${page.nextPage}&search_option=${search_option}&search=${search}">[다음] </a> </c:if> <!-- 마지막 페이지 --> <c:if test="${page.curPage < page.totPage}"> <a href="${path}/board/board_list.do?curPage=${page.totPage}&search_option=${search_option}&search=${search}">[끝] </a> </c:if> </td> </tr> </table> <br> <!-- 검색폼 --> <form method="post" action="${path}/board/board_list.do"> <div align="center"><select name="search_option"> <option value="username" <c:if test= "${search_option =='username'}"> selected </c:if> > 이름 </option> <option value="subject" <c:if test= "${search_option =='subject'}"> selected </c:if> >제목</option> <option value="content" <c:if test= "${search_option =='content'}"> selected </c:if> >내용</option> <option value="all" <c:if test= "${search_option =='all'}"> selected </c:if> >전체</option> </select> <input type="text" name="search" value="${search}"> <input type="submit" value="확인"> <input type="button" id="btnWrite" value="글쓰기"></div> </form> <%-- <a href="${path}/board/write.do">글쓰기</a> --%> </article> <jsp:include page="boardSidebar.jsp" flush="false"/> <jsp:include page="boardFooter.jsp" flush="false"/> | cs |
mapper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | <?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와 중복되지 않는 네임스페이스 기재 --> <mapper namespace="board"> <update id="boardUpdate"> update board set subject=#{subject}, content=#{content},filename=#{filename}, filesize=#{filesize} where idx=#{idx} </update> <delete id="boardDelete"> delete from board where idx=#{idx} </delete> <insert id="replyInsert"> insert into board(idx, userid, subject,content, ref, depth, reorder) values( (select nvl(max(idx)+1,1) from board),#{userid}, #{subject}, #{content},#{ref}, #{depth}, #{reorder} ) </insert> <update id="reorderUpdate"> update board set reorder=reorder+1 where ref=#{ref} and reorder > #{reorder} </update> <select id="commentCount" resultType="int"> select count(*) from board_comment where board_idx=#{board_idx} </select> <insert id="commentInsert"> insert into board_comment(comment_idx,board_idx,userid,content) values( (select nvl(max(comment_idx)+1,1) from board_comment),#{board_idx},#{userid},#{content} ) </insert> <select id="commentList" resultType="commentDto"> select * from( select A.*,rownum as rn from ( select b.comment_idx, b.board_idx, b.userid, m.username, b.content, b.post_date from board_comment b, tbl_member m where b.userid=m.userid and board_idx=#{board_idx} order by comment_idx ) A ) where rn between #{start} and #{end} </select> <update id="hitUp"> update board set hit=hit+1 where idx=#{idx} </update> <select id="boardView" resultType="boardDto"> select * from board where idx = #{idx} </select> <select id="boardList" resultType="boardDto"> select idx,userid,username,subject,hit,post_date,filename,filesize,down,comment_count,ref, depth, reorder from ( select A.*,rownum as rn from ( select b.IDX, m.USERID, m.USERNAME, b.SUBJECT, b.hit, b.POST_DATE, b.filesize, b.filename, b.down, (select count(*) from board_comment where board_idx=b.idx) comment_count ,ref, depth, reorder from board b, TBL_MEMBER m where b.USERID = m.USERID <if test="search_option !='all' "> and ${search_option} like '%'||#{search}||'%' </if> <if test="search_option=='all' "> and (username like '%'||#{search}||'%' or subject like '%' || #{search} ||'%' or content like '%' || #{search} ||'%' ) </if> order by ref desc, reorder asc ) A ) where rn between #{start} and #{end} </select> <insert id="boardInsert"> insert into board(idx, userid, subject,content, ref, filename, filesize,down) values( (select nvl(max(idx)+1,1) from board),#{userid}, #{subject}, #{content},(select nvl(max(idx)+1,1)from board), #{filename}, #{filesize},#{down} ) </insert> <select id="getFilename" resultType="String"> select filename from board where idx=#{idx} </select> <update id="downUp"> update board set down=down+1 where idx=#{idx} </update> <select id="boardCount" resultType="int"> select count(*) from board b, TBL_MEMBER m where b.userid=m.userid <if test="search_option !='all' "> and ${search_option} like '%'||#{search}||'%' </if> <if test="search_option=='all' "> and (username like '%'||#{search}||'%' or subject like '%' || #{search} ||'%' or content like '%' || #{search} ||'%' ) </if> </select> </mapper> | cs |
반응형
'매일코딩 > Spring' 카테고리의 다른 글
24.스프링프로젝트 - download (0) | 2016.11.17 |
---|---|
23.스프링프로젝트 - board write (0) | 2016.11.17 |
21.스프링프로젝트 - 스프링시큐리티 간단 설정 (0) | 2016.11.16 |
20.스프링프로젝트 - 스프링 마이바티스 mysql 연동 (0) | 2016.11.16 |
19.스프링프로젝트 - 화면이동 redirect (0) | 2016.11.01 |
댓글