동적 컨텐츠를 생성하는 방법으로 스프링 MVC(Model, View, Controller) 중 VIEW에 해당한다.
jsp, thymeleaf, Apache Freemarker, Mustache, Groovy Templates 등 여러 템플릿 엔진이 존재한다.
JSP 내에서 자바 코드 사용 가능 (사용하지 못하도록 설정도 가능하나 jsp 내부에 비지니스 로직이 포함된 자바코드 넣는 것 지양 )
서블릿으로 변환되어 실행
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>JSP</title>
</head>
<body>
<div class="container">
    <table class="table">
        <thead>
        <tr>
            <th>번호</th>
            <th>게시물 제목</th>
            <th>작성자</th>
            <th>게시물 내용</th>
            <th>조회수</th>
            <th>추천수</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="board" items="${boardList}" varStatus="status">
            <tr>
                <td><c:out value="${board.boardNo}">${board.boardNo}</c:out></td>
                <td><c:out value="${board.boardNm}">${board.boardNm}</c:out></td>
                <td><c:out value="${board.memberNm}">${board.memberNm}</c:out></td>
                <td><c:out value="${board.boardContent}">${board.boardContent}</c:out></td>
                <td><c:out value="${board.boardViewCnt}">${board.boardViewCnt}</c:out></td>
                <td><c:out value="${board.boardRcmdCnt}">${board.boardRcmdCnt}</c:out></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
</body>
</html>
웹 및 독립형 환경에서 html, xml, js, css 등을 처리할 수 있는 자바 템플릿 엔진이다.
퍼블리셔가 페이지를 생성하거나 수정할 때 웹서버를 실행하지 않고도 오프라인에서 수정 가능하다.
또한 html 엘리먼트 속성으로 값을 넣어주기 때문에 웹 서버를 가동시키지 않아도 브라우저에서 확인 가능하다.
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf</title>
</head>
<body>
<div class="container">
    <table class="table">
        <thead>
        <tr>
            <th>번호</th>
            <th>게시물 제목</th>
            <th>작성자</th>
            <th>게시물 내용</th>
            <th>조회수</th>
            <th>추천수</th>
        </tr>
        </thead>
        <tbody>
        <tr class="text-center" th:each="board : ${boardList}">
            <td> <span th:text="${board.boardNo}"/> </td>
            <td> <span th:text="${board.boardNm}"/> </td>
            <td> <span th:text="${board.getMember().memberNm}"/> </td>
            <td> <span th:text="${board.boardContent}"/> </td>
            <td> <span th:text="${board.boardViewCnt}"/> </td>
            <td> <span th:text="${board.boardRcmdCnt}"/> </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>
JSP를 권장하지 않는 이유
스프링 부트에서 Thymleaf는 자동으로 의존성이 포함되어 있으며 설정 또한 자동으로 지원하는 반면 JSP는 그렇지 않음
아직 thymleaf를 제대로 써보지도 않았고 잘 몰라서 다른건 잘 못느끼겠다. 직접 써보면서 익혀야할 듯!
| JS와 SQL 그리고 JAVA.. 데이터 가공과 비즈니스 로직은 어디에 (0) | 2022.11.22 | 
|---|---|
| [WEB] RESTful API란 (0) | 2021.08.30 | 
| 인자(Argument)와 매개변수(Parameter) (0) | 2021.03.20 | 
| 객체 지향 프로그래밍 (0) | 2021.03.16 | 
| VO vs DAO vs DTO (0) | 2021.03.13 | 
댓글 영역