티스토리 뷰

1. 프로젝트 생성

name : boot06

Dependencies : DevTools, H2, JPA, Thymeleaf, Web

 

2. dependency 추가

링크(클릭)에서 maven탭 코드  

 

1
2
3
4
5
6
<!-- https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect -->
<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>2.3.0</version>
</dependency>
cs

 

위 코드를 pom.xml → pom.xml → <dependencies> 태그 사이에 붙여넣기

 

3. layout 폴더 만들기(p.257)

boot06 → src/main/resources → templates → layout 폴더 만들기

 

링크(클릭)의 책 예제코드 boot05

 

boot05\src\main\resources static 폴더 내용물을  boot 06 → src/main/resources/static에 붙여넣기

boot05\src\main\resources의 template 폴더 내용물을  boot 06 → src/main/resources/template에 붙여넣기 → Overwrite → layout 폴더 하나 남기고 전부 삭제

 

4.부트스트랩

boot06 → src/main/resources → templates → layout → layout.html 에서

 

<head>영역링크(클릭)부트스트랩 CDN 코드 넣기

 

1
2
3
4
5
6
7
8
<!-- 합쳐지고 최소화된 최신 CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
 
<!-- 부가적인 테마 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
 
<!-- 합쳐지고 최소화된 최신 자바스크립트 -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
cs

 

<body> 영역아래 코드 넣기

1
2
3
4
5
6
7
8
<div class="page-header">
    <h1>
        Boot06 Project <small>for Spring MVC + JPA</small>
    </h1>
</div>
<!-- content body -->
<div class="panel panel-default" layout:fragment="content">
</div>
cs

 

google analitics 코드 삭제

 

5. Controller 생성

src/main/java → com.younggeun.board → BoardController 클래스 만들기

 

*BoardController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.younggeun.board;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
@RequestMapping("/boards/")
public class BoardController {
    @GetMapping("/list")
    public void list() {
        System.out.println("called list()");
    }
}
cs

 

6. list.html 만들기

boot06 → src/main/resources → templates → boards폴더 생성 → list.html 파일 생성

 

*list.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
<html xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
    layout:decorate="~{/layout/layout1}">
    
<div layout:fragment="content">
    <div class="panel-heading">List Page</div>
    <div class="panel-body">
        list content
    </div>
</div>
 
<th:block layout:fragment="script">
    <script th:inline="javascript">
    </script>
</th:block>
cs

 

 

 

실행 시킨 후 http://localhost:8080/boards/list  

' > SpringBoot,게시판 만들기' 카테고리의 다른 글

[SpringBoot]5/29  (0) 2018.06.01
[SpringBoot]5/15  (2) 2018.05.24
[SpringBoot]MySQL 설치 및 테스트  (2) 2018.04.27
[SpringBoot]스프링부트 프로젝트 생성하기  (0) 2018.04.27
댓글