jpablog : board list
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
package com.example.jpablog.controller;
|
||||
|
||||
import com.example.jpablog.service.BoardService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class BoardController {
|
||||
|
||||
private final BoardService boardService;
|
||||
|
||||
// 파라미터로 시큐리티 세션 접근 : @AuthenticationPrincipal PrincipalDetail principal
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
public String index(Model model) {
|
||||
model.addAttribute("boards", boardService.글목록());
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -24,4 +25,8 @@ public class BoardService {
|
||||
board.setCount(0);
|
||||
boardRepository.save(board);
|
||||
}
|
||||
|
||||
public List<Board> 글목록() {
|
||||
return boardRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
<div class="container">
|
||||
<div class="card m-2">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">제목</h4>
|
||||
<a href="#" class="btn btn-primary">상세보기</a>
|
||||
</div>
|
||||
<c:forEach var="board" items="${boards}">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user