Spring 프로젝트

프로젝트 게시판 상세보기 페이지

테라시아 2025. 2. 9. 23:33

☆ Code

 

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>글 읽기</title>
    <link rel="stylesheet" href="/css/bootstrap.css">
</head>
<body>
<div class="container">
    <h1 th:text="${vo.title}">제목</h1>
    <hr>
    <p th:text="${vo.content}">내용</p>
    <p>작성자: <span th:text="${vo.writer}"></span></p>
    <p>등록일: <span th:text="${vo.regdate}"></span></p>
    <p>수정일: <span th:text="${vo.updatedate}"></span></p>

    <div class="uploadResult">
        <h3>첨부파일</h3>
        <ul></ul>
    </div>

    <!-- 세션의 로그인 사용자와 작성자 비교 -->
    <div th:if="${session.loginUser != null and session.loginUser.id == vo.writer}">
        <!-- 본인 글인 경우: 수정, 삭제 버튼 노출 -->
        <a th:href="@{'/board/modifyForm'(bno=${vo.bno})}" class="btn btn-warning">수정하기</a>
        <a th:href="@{'/board/remove'(bno=${vo.bno})}" class="btn btn-danger"
           onclick="return confirm('정말 삭제하시겠습니까?')">삭제하기</a>
    </div>
    <div th:if="${session.loginUser == null or session.loginUser.id != vo.writer}">
        <!-- 다른 사용자의 글이면 수정, 삭제 버튼은 숨기고 목록 버튼 노출 -->
        <a href="/board/list" class="btn btn-secondary">목록으로 돌아가기</a>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
<script th:inline="javascript">
    function goUpdate(){
        let bno = [[${vo.bno}]];
        location.href = "/board/modify?bno=" + bno;
    }

    var title = [[${vo.bno}]];
    console.log(title);
    // alert(title);

    let bnoValue = [[${vo.bno}]];
    let ul = $(".uploadResult ul");

    $.getJSON("/board/getAttachList", { bno: bnoValue }, function(arr){
        console.log(arr);
        str = "";

        $(arr).each(function(i, attach) {
            newName = attach.fileName.substring(attach.fileName.indexOf("_")+1);
            str += "<li>" + newName + "</li>";
        });

        ul.html(str);
    });
</script>
</body>
</html>

'Spring 프로젝트' 카테고리의 다른 글

프로젝트 사이드 바  (0) 2025.02.10
프로젝트 글 수정 폼  (0) 2025.02.06
프로젝트 글 작성 폼  (0) 2025.02.05
프로젝트 회원가입 폼  (0) 2025.02.04
Spring UserMapper.xml  (0) 2025.02.03