Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// java code
private BoardRepository boardRepository;

public BoardController(BoardRepository boardRepository) {
    this.boardRepository = boardRepository;
}

@GetMapping("/")
public String index(Model model) {
    model.addAttribute("boardList", boardRepository.findAll());
    return "index";
}

// index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Index</title>
</head>
<body>
<div class="container">
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <a href="/" class="navbar-brand" style="text-decoration:none;">
                    <img th:src="@{/images/spring_boot.png}" class="img-rounded"
                         style="display:inline-block;height:100%;margin-right:5px"/>
                    <span style="vertical-align:middle;">SpringBoot Community Web</span>
                </a>
            </div>
        </div>
    </nav>
</div>

<div class="container">
    <div class="page-header">
        <h1>게시글 목록</h1>
    </div>
    <div class="pull-right" style="width:100px;margin:10px 0;">
        <a href="#" class="btn btn-primary btn-block">등록</a>
    </div>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>#</th>
            <th>서비스 분류</th>
            <th>제목</th>
            <th>작성 날짜</th>
            <th>수정 날짜</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="board : ${boardList}">
            <td th:text="${board.idx}"></td>
            <td th:text="${board.boardType.value}"></td>
            <td th:text="${board.title}"></a></td>
            <td th:text="${board.createdDate} ? ${#temporals.format(board.createdDate,'yyyy-MM-dd HH:mm')} : ${board.createdDate}"></td>
            <td th:text="${board.updatedDate} ? ${#temporals.format(board.updatedDate,'yyyy-MM-dd HH:mm')} : ${board.updatedDate}"></td>
        </tr>
        </tbody>
    </table>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment