jpablog : paging (pageable)
This commit is contained in:
@@ -37,7 +37,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
http
|
||||
.csrf().disable() // csrf 토큰 비활성화
|
||||
.authorizeRequests() // 요청에 대한 인증
|
||||
.antMatchers("/", "/auth/**", "/js/**", "/css/**", "/images/**").permitAll() // 해당 주소로 들어오면 모두 허가
|
||||
.antMatchers("/", "/auth/**", "/js/**", "/css/**", "/images/**", "/dummy/**").permitAll() // 해당 주소로 들어오면 모두 허가
|
||||
.anyRequest().authenticated() // 나머지 요청은 모두 인증을 거쳐야 함
|
||||
.and()
|
||||
.formLogin().loginPage("/auth/loginForm") // 로그인 폼 지정
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.example.jpablog.controller;
|
||||
|
||||
import com.example.jpablog.service.BoardService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -14,8 +17,9 @@ public class BoardController {
|
||||
|
||||
// 파라미터로 시큐리티 세션 접근 : @AuthenticationPrincipal PrincipalDetail principal
|
||||
@GetMapping("/")
|
||||
public String index(Model model) {
|
||||
model.addAttribute("boards", boardService.글목록());
|
||||
public String index(Model model,
|
||||
@PageableDefault(size = 3, sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
model.addAttribute("boards", boardService.글목록(pageable));
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.example.jpablog.model.Board;
|
||||
import com.example.jpablog.model.User;
|
||||
import com.example.jpablog.repository.BoardRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -26,7 +28,7 @@ public class BoardService {
|
||||
boardRepository.save(board);
|
||||
}
|
||||
|
||||
public List<Board> 글목록() {
|
||||
return boardRepository.findAll();
|
||||
public Page<Board> 글목록(Pageable pageable) {
|
||||
return boardRepository.findAll(pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,39 @@
|
||||
|
||||
<div class="container">
|
||||
<div class="card m-2">
|
||||
<c:forEach var="board" items="${boards}">
|
||||
<c:forEach var="board" items="${boards.content}">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">${board.title}</h4>
|
||||
<a href="/api/board/${board.id}" class="btn btn-primary">상세보기</a>
|
||||
</div>
|
||||
</c:forEach>
|
||||
</div>
|
||||
|
||||
<ul class="pagination justify-content-center">
|
||||
<c:choose>
|
||||
<c:when test="${boards.first}">
|
||||
<li class="page-item disabled"><a class="page-link" href="?page=${boards.number -1}">Previous</a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li class="page-item"><a class="page-link" href="?page=${boards.number -1}">Previous</a></li>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<c:choose>
|
||||
<c:when test="${boards.last}">
|
||||
<li class="page-item disabled"><a class="page-link" href="?page=${boards.number + 1}">Next</a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li class="page-item"><a class="page-link" href="?page=${boards.number + 1}">Next</a></li>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
|
||||
<%--<li class="page-item"><a class="page-link" href="#">1</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">2</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">3</a></li>--%>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<%@include file="layout/footer.jsp"%>
|
||||
Reference in New Issue
Block a user