1. 비즈니스 로직
BoardMapper.xml
- 게시글 목록, 게시글 개수를 가져오는 쿼리 작성
<!
<select id="selectBoardList" parameterType="BoardDTO" resultType="BoardDTO">
SELECT
include refid="boardColumns" />
FROM
TB_Board
WHERE
delete_yn = 'N'
ORDER BY
notice_yn ASC,
idx DESC,
insert_time DESC
</select>
<!
<select id="selectBoardTotalCount" parameterType="BoardDTO" resultType="int">
SELECT
COUNT(*)
FROM
tb_board
WHERE
mndelete_yn = 'N'
</select>
BoardMapper.java
public List<BoardDTO> selectBoardList();
public int selectBoardTotalCount();
BoardService.java
public List<BoardDTO> getBoardList();
BoardServiceImpl.java
@Override
public List<BoardDTO> getBoardList() {
List<BoardDTO> boardList = Collections.emptyList();
int boardTotalCount = boardMapper.selectBoardTotalCount();
if(boardTotalCount > 0) {
boardList = boardMapper.selectBoardList();
}
return boardList;
}
BoardController.java
service
에 있는 getBoardList()
를 실행시켜 리스트를 변수에 담아 세팅하고board/list.html
로 이동
@GetMapping(value = "/board/list.do")
public String openBoardList(Model model) {
List<BoardDTO> boardList = boardService.getBoardList();
model.addAttribute("boardList", boardList);
return "board/list";
}
2. 인터페이스
templates/board/write.html
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="board/layout/basic">
<th:block layout:fragment="title">
<title>This page is a list page</title>
</th:block>
<th:block layout:fragment="search">
<form action="#" id="searchform-header" class="searchform js__toggle active pull-right">
<input type="search" placeholder="Search..." class="input-search">
<button class="mdi mdi-magnify button-search" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
</form>
</th:block>
<th:block layout:fragment="content">
<div class="table-responsive clearfix">
<table class="table table-hover">
<thead>
<tr>
<th>번호</th>
<th>제목</th>
<th>작성자</th>
<th>등록일</th>
<th>조회 수</th>
</tr>
</thead>
<tbody>
<tr th:if="${not #lists.isEmpty( boardList )}" th:each="row : ${boardList}">
<td scope="row" th:text="${#strings.equals( row.noticeYn, 'Y' ) ? '공지' : row.idx}"></td>
<td class="text-left">
<a th:href="@{/board/view.do( idx=${row.idx} )}" th:text="${row.title}"></a>
</td>
<td th:text="${row.writer}"></td>
<td th:text="${#temporals.format( row.insertTime, 'yyyy-MM-dd' )}"></td>
<td th:text="${row.viewCnt}"></td>
</tr>
<tr th:unless="${not #lists.isEmpty( boardList )}">
<td colspan="5">조회된 결과가 없습니다.</td>
</tr>
</tbody>
</table>
<div class="btn_wrap text-right">
<a th:href="@{/board/write.do}" class="btn btn-primary waves-effect waves-light">Write</a>
</div>
<th:block layout:fragment="paging">
<nav aria-label="Page navigation" class="text-center">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</th:block>
</div>
</th:block>
</html>
3. 확인
/board/list.do