# 링크와 리다이렉트
## 미션
링크와 리다이렉트를 통해, 페이지간 이동을 연결하시오
![홍팍-스프링-부트-입문--미션](http://drive.google.com/thumbnail?export=view&sz=w960&id=1dzsIuDGvWZsLagH2RIoVP4wMWef0du82)
## 04:20 목록에서 새 글작성 페이지로
#### ../articles/index.mustache
```
{{>layouts/header}}
<table class="table">
...
</table>
<a href="/articles/new">New Article</a>
{{>layouts/footer}}
```
## 05:33 목록페이지로 돌아가기
#### ../articles/new.mustache
```
{{>layouts/header}}
<form class="container" action="/articles/create" method="post">
...
<button type="submit" class="btn btn-primary">Submit</button>
<a href="/articles">Back</a>
</form>
{{>layouts/footer}}
```
## 06:50 리다이렉트 - 새 글저장 후, 상세 페이지로!
#### ../controller/ArticleController
```
...
@Controller
@Slf4j
public class ArticleController {
...
@PostMapping("/articles/create")
public String createArticle(ArticleForm form) {
log.info(form.toString());
Article article = form.toEntity();
log.info(article.toString());
Article saved = articleRepository.save(article);
log.info(saved.toString());
// 리다이렉트 적용: 생성 후, 브라우저가 해당 URL로 재요청
return "redirect:/articles/" + saved.getId();
}
...
}
```
#### ../entity/Article
```
package com.example.firstproject.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Getter // 롬복으로 게터 추가
public class Article {
@Id
@GeneratedValue
private Long id;
@Column
private String title;
@Column
private String content;
}
```
## 10:52 상세 페이지에서 목록으로
#### ../articles/show.mustache
```
{{>layouts/header}}
<table class="table">
...
</table>
<a href="/articles">Go to Article List</a>
{{>layouts/footer}}
```
#### ../articles/index.mustache
```
{{>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><a href="/articles/{{id}}">{{title}}</a></td>
<td>{{content}}</td>
</tr>
{{/articleList}}
</tbody>
</table>
<a href="/articles/new">New Article</a>
{{>layouts/footer}}
```
## 🔥 구글링 훈련하기
- HTML a 태그
- HTTP Redirect란
- @Getter