본문 바로가기
매일코딩/Spring

31.스프링프로젝트 - 조회

by 인생여희 2016. 11. 21.
반응형



view.jsp


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
<%@ 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 }">
                &nbsp;&nbsp;
                </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>
                
                
                <!-- 첨부파일의 사이즈가 보다 크면 파일 다운로드 링크 표시 -->
                
                
                <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>
 
 
<!-- page navigation -->
<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>&nbsp;
    </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="확인">&nbsp;&nbsp;&nbsp;
        <input type="button" id="btnWrite" value="글쓰기"></div>
    </form>    
 
    </article>
          <jsp:include page="boardSidebar.jsp" flush="false"/>
 
          <jsp:include page="boardFooter.jsp" flush="false"/>
 
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
    @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= "기본값"
         */
 
        
        /*total page*/
        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



dao



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
@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;
    }
 
 
 
// 媛쒖떆臾� �쟾泥� 媛쒖닔
    @Override
    public int boardCount(String search_option, String search) {
 
        int result = 0;
 
        try {
            
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("search_option", search_option);
            map.put("search", search);
            
            result = sqlSession.selectOne("boardCount",map);
        } catch (Exception e) {
                e.printStackTrace();
        }
 
        return result;
    }
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
<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>
 
 
 
 
<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>
 
cs


반응형

'매일코딩 > Spring' 카테고리의 다른 글

스프링 기초 DI 예제2  (0) 2018.07.16
스프링 기초 DI 예제1  (0) 2018.07.16
30.스프링프로젝트 - 답변  (4) 2016.11.21
29.spring- detgul  (2) 2016.11.18
28.spring - hitup  (4) 2016.11.18

댓글