mitocondrr
180
2019-02-15 17:55:56 작성 2019-02-15 17:57:11 수정됨
7
473

댓글목록을 불러오고 싶습니다.


전자정부프레임워크로 게시판을 만들어 상세페이지에 댓글기능을 추가하려고 합니다.

댓글 테이블을 별도로 만들어 목록을 불러오고 싶은데 항목 하나씩 조회해서 가져오는건 가능한데

(List<?> 대신 BoardVO로 가져와봤습니다.)

List로 불러오면 나타나지 않습니다.

상세화면에 댓글리스트를 제외한 기존의 게시물 정보는 잘 보여집니다.


Controller

//게시글상세
	@RequestMapping(value="/selectBoard.do")
	public String selectBoard(BoardVO vo, ModelMap model, HttpSession session) throws Exception{
		LOGGER.debug(vo.toString());		
		model.addAttribute("result", boardService.selectBoard(vo, session));
		List<?> list = boardService.repleList(vo);
		model.addAttribute("list", list);
		return "sample/register";
	}


service

//게시글상세
public BoardVO selectBoard(BoardVO vo, HttpSession session) throws Exception;

//댓글목록
List<?> repleList(BoardVO vo) throws Exception;


serviceImpl

//게시글상세
	@Override
	public BoardVO selectBoard(BoardVO vo, HttpSession session) throws Exception {
		LOGGER.debug(vo.toString());
		BoardVO vo2 = updateView(vo);
		session.setAttribute("no", vo2.getNo());
		session.setAttribute("title", vo2.getTitle());
		session.setAttribute("content", vo2.getContent());
		boardMapper.updateCnt(vo);
		return boardMapper.selectBoard(vo);
	}

//댓글목록
	@Override
	public List<?> repleList(BoardVO vo) throws Exception {
		LOGGER.debug(vo.toString());
		return boardMapper.repleList(vo);
	}



mapper

//게시글상세
	public BoardVO selectBoard(BoardVO vo) throws Exception {
		LOGGER.debug(vo.toString());
		return selectOne("board.selectBoard", vo);
	}

//댓글목록
	public List<?> repleList(BoardVO vo) {
		return selectList("board.repleList", vo);
	}



xml


	<select id="repleList" parameterType="BoardVO" resultType="egovMap">
		
		SELECT
			  ROWNUM
			, a.RE_NO AS re_No
			, a.RE_CONTENT AS re_Content
			, a.RE_REGDATE AS re_Regdate
			, b.MEMBERNM AS re_Writer
		FROM REPLE a, MEMBER b
		WHERE BOARDNO=#{no} AND a.RE_WRITER = b.MEMBERID
		ORDER BY ROWNUM ASC
		
	</select>





상세화면.jsp

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form"   uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="ui"     uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><spring:message code="title.list" /></title>
    <link type="text/css" rel="stylesheet" href="<c:url value='/css/egovframework/sample.css'/>"/>
</head>  
<%@include file="menu.jsp" %> 
<script type="text/javaScript" language="javascript" defer="defer">
        <!--
        //*검색*/
		function fn_repleSave(){
			var re_Content = document.getElementById("re_Content")
			
					if(re_Content.value == " "){
						alert("댓글 내용을 입력하세요.");
						re_Content.focus();
						return;
					} else {
						document.repleForm.action = "<c:url value='/boardList.do'/>";
						document.repleForm.submit();			
					}
        } 
        
        //-->
    </script>
<body style="text-align:center; margin:0 auto; display:inline; padding-top:100px;">
        <div id="content_pop">
        	<!-- 타이틀 -->
        	<div id="title">
        		<ul>
        			<li><img src="<c:url value='/images/egovframework/example/title_dot.gif'/>" alt=""/>
        				<spring:message code="title.detail" />
        			</li>
        		</ul>
        	</div>
        	<!-- 상세-->
        	<div id="table">
    		<table width="100%" border="1" cellpadding="0" cellspacing="0" style="bordercolor:#D3E2EC; bordercolordark:#FFFFFF; BORDER-TOP:#C2D0DB 2px solid; BORDER-LEFT:#ffffff 1px solid; BORDER-RIGHT:#ffffff 1px solid; BORDER-BOTTOM:#C2D0DB 1px solid; border-collapse: collapse;">
	    	<colgroup>
    			<col width="100"/>
    			<col width="?"/>
    			<col width="100"/>
    			<col width="?"/>
    			<col width="100"/>
    			<col width="?"/>
    		</colgroup>
    			<tr>
	    			<td class="tbtd_caption"><label for="writer"><spring:message code="title.writer" /></label></td>
	    			<td class="tbtd_content">
	    				${result.writer}
	    			</td>
	    			<td class="tbtd_caption"><label for="regdate"><spring:message code="title.regdate" /></label></td>
	    			<td class="tbtd_content">
	    				<fmt:formatDate value="${result.regdate}" pattern="yyyy-MM-dd" />
	    			</td>
	    			<td class="tbtd_caption"><label for="viewcnt"><spring:message code="title.viewcnt" /></label></td>
	    			<td class="tbtd_content">
	    				${result.viewcnt}
	    			</td>
	    		</tr>
        		<tr>
        			<td class="tbtd_caption"><label for="title"><spring:message code="title.title" /></label></td>
        			<td class="tbtd_content" colspan="5">
						${result.title}
					</td>

        		</tr>        	
	    		<tr>
	    			<td class="tbtd_caption"><label for="content"><spring:message code="title.content" /></label></td>
	    			<td class="tbtd_content" colspan="5">
	    				${result.content}
	    			</td>
	    		</tr>
    		</table>
           	</div>
        		<div id="sysbtn">
	        	  <ul>
	        	  	  <li>
	        	         <span class="btn_blue_l">
	        	              <a href="/boardList.do"><spring:message code="button.list" /></a>
	                          <img src="<c:url value='/images/egovframework/example/btn_bg_r.gif'/>" style="margin-left:6px;" alt=""/>
	                     </span>
	                  </li>
	             <c:if test="${result.writer == sessionScope.memberNm}">
	        	      <li>
	        	         <span class="btn_blue_l">
	        	              <a href="/updateView.do"><spring:message code="button.modify" /></a>
	                          <img src="<c:url value='/images/egovframework/example/btn_bg_r.gif'/>" style="margin-left:6px;" alt=""/>
	                     </span>
	                  </li>
	                  <li>
	        	         <span class="btn_blue_l">
	        	              <a href="/deleteBoard.do?deleteNo=${result.no}"><spring:message code="button.delete" /></a>
	                          <img src="<c:url value='/images/egovframework/example/btn_bg_r.gif'/>" style="margin-left:6px;" alt=""/>
	                     </span>
	                  </li>
	              </c:if>
	              </ul>
	        	</div>
	        <!-- 타이틀 -->
        	<div id="title">
        		<ul>
        			<li><img src="<c:url value='/images/egovframework/example/title_dot.gif'/>" alt=""/>
        				<spring:message code="title.reple" />
        			</li>
        		</ul>
        	</div>
        	<!-- 댓글리스트 -->
        	<div id="table">
    		<table width="100%" border="1" cellpadding="0" cellspacing="0" style="bordercolor:#D3E2EC; bordercolordark:#FFFFFF; BORDER-TOP:#C2D0DB 2px solid; BORDER-LEFT:#ffffff 1px solid; BORDER-RIGHT:#ffffff 1px solid; BORDER-BOTTOM:#C2D0DB 1px solid; border-collapse: collapse;">
	    	<colgroup>
    			<col width="80"/>
    			<col width="?"/>
    			<col width="70"/>
    		</colgroup>   
    		<c:forEach var="list" items="${list}" varStatus="status">   			
	    		<c:if test="${list.re_Writer == sessionScope.memberNm}">
				<tr>	
        			<td class="tbtd_caption">
						<font color="red"><c:out value="${list.re_Writer}"/></font>
					</td>
					<td colspan="2" class="tbtd_content">
						<fmt:formatDate value="${list.re_Regdate}" pattern="yyyy-MM-dd" />    
					</td>
	    		</tr>
	    		<tr>
	    			<td colspan="2" align="left" class="tbtd_content">
	    				<c:out value="${list.re_Content}"/>
	    			</td>
	    			<td class="tbtd_content">
		    			<span class="btn_blue_l">
		        	        <a href="/deleteReple.do?re_No=${list.re_No}"><spring:message code="button.delete" /></a>
		                    <img src="<c:url value='/images/egovframework/example/btn_bg_r.gif'/>" style="margin-left:6px;" alt=""/>
		                </span>
	    			</td>
	    		</tr>
	    		</c:if>
	    		<c:if test="${list.re_Writer != sessionScope.memberNm}">
				<tr>	
        			<td class="tbtd_caption">
						<c:out value="${list.re_Writer}"/>
					</td>
					<td class="tbtd_content">
						<fmt:formatDate value="${list.re_Regdate}" pattern="yyyy-MM-dd" />    
					</td>
	    		</tr>
	    		<tr>
	    			<td class="tbtd_content" colspan="2">
	    				<c:out value="${list.re_Content}"/>
	    			</td>
	    		</tr>
	    		</c:if>   
	    	</c:forEach>	    	
    		</table>
           	</div>
            <!-- 댓글작성 -->
        	<div id="table">
        	 <form:form commandName="boardVO" id="repleForm" name="repleForm" method="post">
    		<table width="100%" border="1" cellpadding="0" cellspacing="0" style="bordercolor:#D3E2EC; bordercolordark:#FFFFFF; BORDER-TOP:#C2D0DB 2px solid; BORDER-LEFT:#ffffff 1px solid; BORDER-RIGHT:#ffffff 1px solid; BORDER-BOTTOM:#C2D0DB 1px solid; border-collapse: collapse;">
	    	<colgroup>
    			<col width="?"/>
    			<col width="100"/>
    		</colgroup>
        		<tr>
        			<td class="tbtd_content" colspan="4">
        				<form:hidden path="no" value="${sessionScope.no}"/>
						<form:textarea path="re_Content" id="re_Content" rows="5" cols="90" />
					</td>
					<td class="tbtd_content">
						 <span class="btn_blue_l">
	        	              <a href="javascript:fn_repleSave();"><spring:message code="button.create" /></a>
	                          <img src="<c:url value='/images/egovframework/example/btn_bg_r.gif'/>" style="margin-left:6px;" alt=""/>
	                     </span>
					</td>
        		</tr>        	
    		</table>
    		</form:form>
           	</div>
	        </div>
</body>
</html>
0
0
  • 답변 7

  • 어쩌다
    4k
    2019-02-15 17:58:43

    에러가 안난다면 댓글이 없는거 아닌가요.?

    0
  • 륜디아
    1k
    2019-02-15 17:59:58

    1. 댓글을 가져올때 사용할 원글 번호 인덱스라던지의 값이 잘 넘어가는지 확인.

    2. 쿼리 돌린뒤에 값이 잘 리턴되는지 확인.

    3. jsp로 잘 넘어가는지 확인.

    0
  • mitocondrr
    180
    2019-02-15 18:04:05

    댓글은 존재하구 원글 번호 넘어가는것도 확인 했어용... 

    쿼리는 문제 없는지 확인 했는데 가져온 값 리턴되는지 확인하는 법을 몰라요ㅠㅜ

    0
  • 륜디아
    1k
    2019-02-15 18:06:44
    List<?> list = boardService.repleList(vo);
    list에 값 들어있나 찍어보세요
    0
  • 륜디아
    1k
    2019-02-15 18:10:20

    안들어있다면 service부분부터 어느부분이 문제인지 찍어보시고, 들어있으면 jsp에서 받아오는 부분 보시면 됩니다.

    0
  • 사는게힘듭니다
    1k
    2019-02-15 21:24:42

    xml쪽에 resultType이 hashmap아닌가요?:

    0
  • mitocondrr
    180
    2019-02-18 09:10:35 작성 2019-02-18 09:17:44 수정됨
    jsp에서 값 이름을 대문자로 바꿔 해결했습니다~~
    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.