⁂ Spring FrameWork/: 기본 익히기(Boot 기반)

[Spring] #7-3 MVC 패턴으로 DB 접근하기 - MyMelon 프로젝트(JSP파일)

김갱환 2022. 11. 2. 16:51

1. View 페이지 작업하기

 

 DB에서 쓸 자료들도 변수로 잘 담아왔겠다, 이젠 목록을 담을 뷰페이지를 구성해보려 한다.

 우선 완성된 코드를 먼저 올린 뒤 안에 쓰인 내용들을 차근차근 살펴보자.

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>list.jsp</title>
	<style>
		*{ font-family : gulim; font-size: 24px; }
	</style>
	<link href="../css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<div class="title">미디어 그룹 목록</div>
	<div class="content">
		<input type="button" value="그룹 등록" onclick="location.href='create.do'">
	</div>
	
	<c:if test="${requestScope.count==0}">
		<table><tr><td>게시판에 글 없음!!</td></tr></table>
	</c:if>
	
	<c:if test="${requestScope.count>0}">
		<table>
		<tr>
			<th>그룹 번호</th>
			<th>그룹 제목</th>
			<th>수정/삭제</th>
		</tr>
		
		<c:forEach var="dto" items="${list}"> <%-- for(dto : ${list}) --%>
			<tr>
				<td>${dto.mediagroupno}</td>
				<td>${dto.title}</td>
				<td>
					<input type="button" value="수정">
					<input type="button" value="삭제">
				</td>
			</tr>		
		</c:forEach>
		</table>
	</c:if>
</body>
</html>

 

 

1) <c:if test="${requestScope.count==0}"> / <c:if test="${requestScope.count>0}">

  count 변수에 담았던, 전체 행 개수가 0일 때와 0 이상일 때로 나누어서 목록이 표기되게 하였다.

 

2) <c:forEach var="dto" items="${list}">

 여기서 var="dto"는 DTO 클래스의 setter 함수와 반응하게 되고, 담겨진 것들은 꺼내게 된다.