Programming/스프링(spring) - Enterprise

스프링(spring)/ +더하기 5(관전 시스템)

esoog Polaris 2023. 8. 7. 14:52
반응형

1. 먼저 해당 게시글을 토대로 생성된 1:1 매칭을 댓글처럼 모두 나열 시켜본다.

먼저 jsp파일에 링크 추가

 

			<a href="/board/debateNest?idx=${list.idx}">논쟁 둥지</a>

 

 

 

 

 

2. Controller단에서 url매핑

 

// 논쟁 둥지
	@RequestMapping(value = "/debateNest", method = RequestMethod.GET)
	public void getDebateNest(@RequestParam("idx") int idx, Model model) throws Exception {
		List<BoardVO> debateNest = null;
		debateNest = service.debateNest(idx);
		model.addAttribute("debateNest", debateNest);

		List<BoardVO> originList = null;
		originList = service.originList(idx);
		model.addAttribute("originList", originList);
	}

 

 

 

 

 

3. 그리고 DAO와 Service파일에 아래 코드 추가

 

	public List<BoardVO> debateNest(int idx) throws Exception;

 

 

DAOImpl파일에는

 

@Override
	public List<BoardVO> debateNest(int idx) throws Exception {
		HashMap<String, Object> data = new HashMap<>();
		data.put("idx", idx);
		return sql.selectList(namespace + ".getDebateNest", idx);
	}

 

 

ServiceImpl파일에는

 

@Override
	public List<BoardVO> debateNest(int idx) throws Exception {
		return dao.debateNest(idx);
	}

 

 

 

 

 

4. 그리고 매퍼파일~

<select id="getDebateNest" resultType="com.project.model.BoardVO">
		SELECT * FROM
		argument
		WHERE
		idx=#{idx}
		ORDER BY date DESC
	</select>

*해당 게시물idx로 행성된 모든 레코드 셀렉트

 

 

 

 

5. debateNest.jsp파일에 아래 코드를 추가

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<link rel="stylesheet" href="../../resources/debateNest.css">
<!-- 합쳐지고 최소화된 최신 CSS -->
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- 부가적인 테마 -->
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

<script
	src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<title>작성</title>
</head>
<body>

	<c:if test="${member == null}">
		<script>
			alert("로그인을 해야 작성이 가능합니다.");
			window.location.href = '/'; // 여기서 '/페이지'는 이동하고자 하는 페이지의 URL입니다.
		</script>
	</c:if>

	<div class="contentBox">
		<c:forEach items="${originList}" var="originList">
			<div class="themeBox">
				<h1>최초 논점</h1>
				<div>
					<fmt:formatDate value="${originList.date}"
						pattern="yyyy-MM-dd HH:mm:ss" />
				</div>
				<div>${originList.nick}</div>
				<div>${originList.text}</div>
				<div>${originList.hcount}</div>
			</div>
			<c:set var="originListNick" value="${originList.nick}"></c:set>
			<c:set var="originListIdx" value="${originList.idx}"></c:set>
		</c:forEach>
		<c:forEach items="${debateNest}" var="debateNest">
			<c:if test="${debateNest.nick==originListNick}">
				<div class="originBox">
					<div>
						<fmt:formatDate value="${debateNest.date}"
							pattern="yyyy-MM-dd HH:mm:ss" />
					</div>
					<div>${debateNest.nick}</div>
					<div>${debateNest.text}</div>
					<div>${debateNest.hcount}</div>
				</div>
			</c:if>
			<c:if test="${debateNest.nick==member.id}">
				<div class="userBox">
					<div>
						<fmt:formatDate value="${debateNest.date}"
							pattern="yyyy-MM-dd HH:mm:ss" />
					</div>
					<div>${debateNest.nick}</div>
					<div>${debateNest.text}</div>
					<div>${debateNest.hcount}</div>
				</div>
			</c:if>
			<c:if test="${debateNest.nick!=member.id && debateNest.nick!=originListNick}">
				<div class="newBox">
					<div>
						<fmt:formatDate value="${debateNest.date}"
							pattern="yyyy-MM-dd HH:mm:ss" />
					</div>
					<div>${debateNest.nick}</div>
					<div>${debateNest.text}</div>
					<div>${debateNest.hcount}</div>
					<a
						href="/board/debate3?idx=${debateNest.idx}&sender=${debateNest.nick}">1:1구경</a>
				</div>
			</c:if>
		</c:forEach>
	</div>

</body>
</html>

 

 

 

 

 

6. 자, 그럼 여기 전체 목록에서 1:1매칭 관전 시스템으로 넘어가기.

위에 jsp파일 하단부에 보면 이게 있다.

 

<a href="/board/debate3?idx=${debateNest.idx}&sender=${debateNest.nick}">1:1구경</a>

 

 

 

 

 

7. Controller 단~

 

// 논쟁 3자 구경
	@RequestMapping(value = "/debate3", method = RequestMethod.GET)
	public void getDebate3(@RequestParam("idx") int idx, @RequestParam("sender") String sender,Model model) throws Exception {
		// 그러니까 기존 주제 최초 발언 게시글 데이터
		List<BoardVO> originList = null;
		originList = service.originList(idx);
		model.addAttribute("originList", originList);

		List<BoardVO> debate = null;
		debate = service.debate(idx, sender);
		model.addAttribute("debate", debate);
	}

*데이터 처리에 새로 생성할 것이 없기에 따로 DAO VO를 건드릴 필요가 없다.

 

 

 

 

8. 보여주기 jsp파일만 만들어주면 된다.

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<link rel="stylesheet" href="../../resources/debate.css">
<!-- 합쳐지고 최소화된 최신 CSS -->
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- 부가적인 테마 -->
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

<script
	src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<title>작성</title>
</head>
<body>

	<c:if test="${member == null}">
		<script>
			alert("로그인을 해야 작성이 가능합니다.");
			window.location.href = '/'; // 여기서 '/페이지'는 이동하고자 하는 페이지의 URL입니다.
		</script>
	</c:if>

	<div class="contentBox">
		<c:forEach items="${debate}" var="debate">
			<c:if test="${debate.nick==member.id}">
				<div class="originBox">
					<div>
						<fmt:formatDate value="${debate.date}"
							pattern="yyyy-MM-dd HH:mm:ss" />
					</div>
					<div>${debate.nick}</div>
					<div>${debate.text}</div>
					<div>${debate.hcount}</div>
				</div>
			</c:if>
			<c:if test="${debate.nick!=member.id}">
				<div class="newBox">
					<div>
						<fmt:formatDate value="${debate.date}"
							pattern="yyyy-MM-dd HH:mm:ss" />
					</div>
					<div>${debate.nick}</div>
					<div>${debate.text}</div>
					<div>${debate.hcount}</div>
				</div>
			</c:if>
		</c:forEach>
		<c:forEach items="${originList}" var="originList">
			<div class="userBox">
			<h1>최초 논점</h1>
				<div>
					<fmt:formatDate value="${originList.date}"
						pattern="yyyy-MM-dd HH:mm:ss" />
				</div>
				<div>${originList.nick}</div>
				<div>${originList.text}</div>
				<div>${originList.hcount}</div>
			</div>
			<c:set var="originListNick" value="${originList.nick}"></c:set>
			<c:set var="originListIdx" value="${originList.idx}"></c:set>
		</c:forEach>
	</div>
</body>
</html>

확인. 나이스

728x90