![article thumbnail image](https://blog.kakaocdn.net/dn/csQZtM/btrTaNHJ3WW/mwFsayfJa2PFZJBmIkKA31/img.png)
728x90
브라우저 요청 받기
모델과 데이터 등록 - addAttribute()
@GetMapping("/articles")
public String index(Model model){
// 1. 모든 Article을 가져온다
List<Article> articleEntityList = articleRepository.findAll();
// 2. 가져온 Article 묶음을 뷰로 전달!
model.addAttribute("articleList", articleEntityList);
// 3. 뷰페이지를 설정!
return "articles/index"; //articles/index.mustache
}
라파지터리 오버라이딩 - findAll()
public interface ArticleRepository extends CrudRepository<Article,Long> {
// CrudRepository<관리대상 엔티티: Article, 대표값의 타입(id) : Long>
@Override
ArrayList<Article> findAll();
}
뷰 페이지 연결 및 작성
{{>layouts/header}}
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Content</th>
</tr>
</thead>
<tbody>
{{#articleList}}
<tr>
<th>{{id}}</th>
<td>{{title}}</td>
<td>{{content}}</td>
</tr>
{{/articleList}}
</tbody>
</table>
{{>layouts/footer}}
728x90
'Study > SpringBoot WebProject' 카테고리의 다른 글
Spring Boot 수정 폼 만들기 (0) | 2022.12.09 |
---|---|
Spring Boot 링크와 리다이렉트 (0) | 2022.12.09 |
Spring boot 데이터 조회하기 with JPA (0) | 2022.12.09 |
Spring Boot lombok과 refactoring (1) | 2022.11.03 |
Spring Boot DB테이블과 SQL (0) | 2022.11.03 |