Posts spring_project-5. 스프링 프로젝트(리스트)
Post
Cancel

spring_project-5. 스프링 프로젝트(리스트)

왜 리스트부분 현제 회원이게시한 게시물을 보여주고 작성자명을 조건에들어가고

1
2
 ORDER BY A.HIBBS_GROUP DESC, A.HIBBS_ORDER ASC))

댓글때문에 bbs seq가 증가하는데 부모기준으로 묶여서증가해야하기때문에 group으로 묶어줘서 내림차순으로 해주었다

여기를 자세히 봐야할것 파일에서 데이터를 가져와서 rownum을 메겨준후 order by를 해주면 다섞인다

그후 다시 맨마지막에

1
2
WHERE RNUM <![CDATA[>=]]> #{startRow}
    AND RNUM <![CDATA[<=]]> #{endRow}

다시 로우넘 처리를 해준다

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
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/views/include/head.jsp" %>
<script type="text/javascript">
$(document).ready(function() {
    
	$("#btnWrite").on("click", function() {
		
		document.bbsForm.hiBbsSeq.value = "";
		document.bbsForm.action = "/board/writeForm";
		document.bbsForm.submit();
		
	});
	
	$("#btnSearch").on("click", function() {
		
		document.bbsForm.hiBbsSeq.value = "";
		document.bbsForm.searchType.value = $("#_searchType").val();
		document.bbsForm.searchValue.value = $("#_searchValue").val();
		document.bbsForm.curPage.value = "1";
		document.bbsForm.action = "/board/list";
		document.bbsForm.submit();
		
	});
});
 
function fn_view(bbsSeq)
{
	document.bbsForm.hiBbsSeq.value = bbsSeq;
	document.bbsForm.action = "/board/view";
	document.bbsForm.submit();
}

function fn_list(curPage)
{
	document.bbsForm.hiBbsSeq.value = "";
	document.bbsForm.curPage.value = curPage;
	document.bbsForm.action = "/board/list";
	document.bbsForm.submit();	
}
</script>
</head>
<body>
<%@ include file="/WEB-INF/views/include/navigation.jsp" %>
<div class="container">
	
	<div class="d-flex">
      <div style="width:50%;">
         <h2>게시판</h2>
      </div>
      <div class="ml-auto input-group" style="width:50%;">
         <select name="_searchType" id="_searchType" class="custom-select" style="width:auto;">
				<option value="">조회 항목</option>
				<option value="1" <c:if test ="${searchType eq '1'}">selected</c:if>>작성자</option>
				<option value="2" <c:if test ="${searchType eq '2'}"> selected></c:if>>제목</option>
				<option value="3" <c:if test="${searchType eq '3'}"> selected></c:if>>내용</option>
			</select>
			<input type="text" name="_searchValue" id="_searchValue" value="${searchValue}" class="form-control mx-1" maxlength="20" style="width:auto;ime-mode:active;" placeholder="조회값을 입력하세요." />
			<button type="button" id="btnSearch" class="btn btn-secondary mb-3 mx-1">조회</button>
      </div>
 	</div>
 	
	<table class="table table-hover">
		<thead>
		<tr style="background-color: #dee2e6;">
			<th scope="col" class="text-center" style="width:10%">번호</th>
			<th scope="col" class="text-center" style="width:55%">제목</th>
			<th scope="col" class="text-center" style="width:10%">작성자</th>
			<th scope="col" class="text-center" style="width:15%">날짜</th>
			<th scope="col" class="text-center" style="width:10%">조회수</th>
		</tr>
		</thead>
		<tbody>
		
		
		<tr>
			<td class="text-center"></td>
			<td>
				<a href="javascript:void(0)" onclick="fn_view()">

				</a>
			</td>
			<td class="text-center"></td>
			<td class="text-center"></td>
			<td class="text-center"></td>
		</tr>
		</tbody>
		<tfoot>
		<tr>
            <td colspan="5"></td>
        </tr>
         
        
		</tfoot>
	</table>
	<nav>
		<ul class="pagination justify-content-center">

			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list()">이전블럭</a></li>

	
			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list()">1</a></li>

			
			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list()">다음블럭</a></li>
		</ul>
	</nav>
	
	<button type="button" id="btnWrite" class="btn btn-secondary mb-3">글쓰기</button>
	
	<form name="bbsForm" id="bbsForm" method="post">
		<input type="hidden" name="hiBbsSeq" value="" />
		<input type="hidden" name="searchType" value="" />
		<input type="hidden" name="searchValue" value="" />
		<input type="hidden" name="curPage" value="" />
	</form>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<c:if test="${!empty list}">
	<c:forEach var="hiBoard" items="${list}" valStatus="status">
		<tr>
			<td class="text-center"></td>
			<td>
				<a href="javascript:void(0)" onclick="fn_view()">

				</a>
			</td>
			<td class="text-center"></td>
			<td class="text-center"></td>
			<td class="text-center"></td>
		</tr>
	</c:forEach>
</c:if>

댓글일 경우에는 순번이 안들어가게끔 넣어줘야한다

댓글이달렸을때

1
2
HIBBS_SEQ 는 3이라면  HIBBSGROUP, ORDER, INDENT는 증가하지않는다
이런것을 처리할때사용한다

indent가 0이아닐때는 번호를 매기지않는다

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

  1. search box가 잘 검색되는지 확인해본다

그후 페이지 처리를 해준다

list jsp

이클립스에서 112 라인 부터 수정을 해줬다

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
	<nav>
		<ul class="pagination justify-content-center">
<c:if test="${!empty paging}">
	<c:if test="${paging.prevBlockPage gt 0}">
			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list(${paging.prevBlockPage})">이전블럭</a></li>
	</c:if>
	<c:forEach var="i" begin="${paging.startPage}" end="${paging.endPage}">
		<c:choose>
			<c:when test="${i ne curPage}">
			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list(${i})">${i}</a></li>
			</c:when>
			<c:otherwise>
			<li class="page-item active"><a class="page-link" href="javascript:void(0)" style="cursor:default;">${i}</a></li>
			</c:otherwise>
		</c:choose>
	</c:forEach>
			
	<c:if test="${paging.nextBlockPage gt 0}">
			<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="fn_list(${paging.nextBlockPage})">다음블럭</a></li>
	</c:if>
</c:if>
		</ul>
	</nav>
	
	<button type="button" id="btnWrite" class="btn btn-secondary mb-3">글쓰기</button>
	
	<form name="bbsForm" id="bbsForm" method="post">
		<input type="hidden" name="hiBbsSeq" value="" />
		<input type="hidden" name="searchType" value="${searchType}" />
		<input type="hidden" name="searchValue" value="${searchValue}" />
		<input type="hidden" name="curPage" value="${curPage}" />
	</form>
</div>

그다음 HiBoardController에가서 49행에 숫자만고쳐준다

1
2
	private static final int LIST_COUNT = 3;
	private static final int PAGE_COUNT = 3;

페이지를 3페이씩만보여줘서 적은데이터로 값을 확인하기위해서 수정하였다

hiBoardController list jsp

호출할 컨트롤러를 만들어준다

1
2
3
4
5
6
//게시물 조회
	@RequestMapping(value="/board/view")
	public String view(ModelMap model, HttpServletRequest request, HttpServletResponse response)
	{
		return "/board/view";
	}

view jsp

board 폴더밑에 view jsp파일을 만든다

주의사항 맨마지막에보내준 view jsp파일로 받는다

hiBoardController list 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
//게시물 조회
	@RequestMapping(value="/board/view")
	public String view(ModelMap model, HttpServletRequest request, HttpServletResponse response)
	{
		
		//쿠키값
		String cookieUserId = CookieUtil.getHexValue(request, AUTH_COOKIE_NAME);
		//게시물 번호
		long hiBbsSeq = HttpUtil.get(request, "hiBbsSeq", (long)0);
		//조회항목(1.작성자, 2.제목, 3.내용)
		String searchType = HttpUtil.get(request, "searchType");
		//조회값
		String searchValue = HttpUtil.get(request, "searchValue", "");
		//현재페이지
		long curPage = HttpUtil.get(request, "curPage", (long)1);
		//본인글 여부
		String boardMe = "N";
		
		HiBoard hiBoard = null;
		
		if(hiBbsSeq > 0)
		{
			
		}
		
		return "/board/view";
	}

그후 SQL문 가공을한다

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
SELECT
    A.HIBBS_SEQ,
    A.USER_ID,
    B.USER_NAME,
    B.USER_EMAIL,
    A.HIBBS_GROUP,
    A.HIBBS_ORDER,
    A.HIBBS_INDENT,
    A.HIBBS_TITLE,
    A.HIBBS_CONTENT,
    A.HIBBS_READ_CNT,
    A.REG_DATE,
    A.HIBBS_PARENT
FROM
    TBL_HIBOARD A, TBL_USER B
WHERE
    A.HIBBS_SEQ = 10
AND 
     A.USER_ID = B.USER_ID;
     
     
     이렇게 한다음 데이터확인하고
     
SELECT
    A.HIBBS_SEQ AS HIBBS_SEQ,
    NVL(A.USER_ID, '') AS USER_ID,
    NVL(B.USER_NAME, '') AS USER_NAME,
    NVL(B.USER_EMAIL, '') AS USER_EMAIL,
    NVL(A.HIBBS_GROUP, 0) AS HIBBS_GROUP,
    NVL(A.HIBBS_ORDER, 0) AS HIBBS_ORDER,
    NVL(A.HIBBS_INDENT, 0) AS HIBBS_INDENT,
    NVL(A.HIBBS_TITLE, '') AS HIBBS_TITLE,
    NVL(A.HIBBS_CONTENT, '') AS HIBBS_CONTENT,
    NVL(A.HIBBS_READ_CNT, 0) AS HIBBS_READ_CNT,
    NVL(TO_CHAR(A.REG_DATE, 'YYYY.MM.DD HH24:MI:SS'), '') AS REG_DATE,
    NVL(A.HIBBS_PARENT, 0) AS HIBBS_PARENT
FROM
    TBL_HIBOARD A, TBL_USER B
WHERE
    A.HIBBS_SEQ = 10
AND 
    A.USER_ID = B.USER_ID;
    
    이렇게까지 만들어놓는다
     
     

만약에 WHERE 조건에 BBSSEQ를 설정을 안해준다면 여기서 마지막조건에 B USER ID가 왼쪽으로 설정해주는것이더좋다 왜냐하면 TBL USER가 기준이 되는 테이블이므로 왼쪽에설정하고 오른쪽에는 대입한다라는 개념을 해주면좋다

이용어가 드라이빙 테이블이라고한다 조금더 알아봐야할거같다

HiBoardDao xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- 게시물 조회 -->
<select id="boardSelect" parameterType="long" resultMap="hiBoardResultMap">
	SELECT
	    A.HIBBS_SEQ AS HIBBS_SEQ,
	    NVL(A.USER_ID, '') AS USER_ID,
	    NVL(B.USER_NAME, '') AS USER_NAME,
	    NVL(B.USER_EMAIL, '') AS USER_EMAIL,
	    NVL(A.HIBBS_GROUP, 0) AS HIBBS_GROUP,
	    NVL(A.HIBBS_ORDER, 0) AS HIBBS_ORDER,
	    NVL(A.HIBBS_INDENT, 0) AS HIBBS_INDENT,
	    NVL(A.HIBBS_TITLE, '') AS HIBBS_TITLE,
	    NVL(A.HIBBS_CONTENT, '') AS HIBBS_CONTENT,
	    NVL(A.HIBBS_READ_CNT, 0) AS HIBBS_READ_CNT,
	    NVL(TO_CHAR(A.REG_DATE, 'YYYY.MM.DD HH24:MI:SS'), '') AS REG_DATE,
	    NVL(A.HIBBS_PARENT, 0) AS HIBBS_PARENT
	FROM
	    TBL_HIBOARD A, TBL_USER B
	WHERE
	    A.HIBBS_SEQ = ${value}
	AND 
	    A.USER_ID = B.USER_ID;
</select>

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

게시물 조회수 서비스 HiBoardService 구현

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//게시물 보기
	public HiBoard boardView(long hiBbsSeq)
	{
		HiBoard hiBoard = null;
		
		try
		{
			hiBoard = hiBoardDao.boardSelect(hiBbsSeq);
			
			if(hiBoard != null)
			{
				//조회수 증가
				
			}
		}
		catch(Exception e)
		{
			logger.error("[HiBoardService] boardView Exception", e);
		}
		return hiBoard;
	}
1
2
3
4
5
6
<!-- 게시물 조회수 증가 -->
<update id="boardReadCntPlus" parameterType="long">
UPDATE TBL_HIBOARD
    SET HIBBS_READ_CNT = HIBBS_READ_CNT + 1
WHERE HIBBS_SEQ = #{value}
</update>

첨부파일 서비스 구현

XML 구현하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<select id="boardFileSelect" parameterType="long"  resultMap="hiBoardFileResultMap">
SELECT
    HIBBS_SEQ,
    FILE_SEQ,
    NVL(FILE_ORG_NAME, '') AS FILE_ORG_NAME,
    NVL(FILE_NAME, '') AS FILE_NAME,
    NVL(FILE_EXT, '') AS FILE_EXT,
    NVL(FILE_SIZE, 0) AS FILE_SIZE,
    NVL(TO_CHAR(REG_DATE, 'YYYY.MM.DD HH24:MI:SS'), '') AS REG_DATE
FROM
    TBL_HIBOARD_FILE
WHERE
    HIBBS_SEQ = #{value}
AND
    FILE_SEQ = 1
</select>

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
//게시물 조회
	@RequestMapping(value="/board/view")
	public String view(ModelMap model, HttpServletRequest request, HttpServletResponse response)
	{
		
		//쿠키값
		String cookieUserId = CookieUtil.getHexValue(request, AUTH_COOKIE_NAME);
		//게시물 번호
		long hiBbsSeq = HttpUtil.get(request, "hiBbsSeq", (long)0);
		//조회항목(1.작성자, 2.제목, 3.내용)
		String searchType = HttpUtil.get(request, "searchType");
		//조회값
		String searchValue = HttpUtil.get(request, "searchValue", "");
		//현재페이지
		long curPage = HttpUtil.get(request, "curPage", (long)1);
		//본인글 여부
		String boardMe = "N";
		
		HiBoard hiBoard = null;
		
		if(hiBbsSeq > 0)
		{
			hiBoard = hiBoardService.boardView(hiBbsSeq);
			
			if(hiBoard != null && StringUtil.equals(hiBoard.getUserId(), cookieUserId))
			{
				boardMe = "Y"; //본인 글
			}
		}
		model.addAttribute("hiBbsSeq", hiBbsSeq);
		model.addAttribute("hiBoard", hiBoard);
		model.addAttribute("boardMe", boardMe);
		model.addAttribute("searchType", searchType);
		model.addAttribute("searchValue", searchValue);
		model.addAttribute("curPage", curPage);
		
		return "/board/view";
	}

게시물 삭제

This post is licensed under CC BY 4.0 by the author.