728x90

링크 걸기 - a 태그

{{>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>
    {{#article}}
        <tr>
            <th>{{id}}</th>
            <td>{{title}}</td>
            <td>{{content}}</td>
        </tr>
    {{/article}}
    </tbody>
</table>
<a href="/articles/{{article.id}}/edit" class="btn btn-primary">Edit</a>
<a href="/articles">Go to Article List</a>

{{>layouts/footer}}

수정 페이지 작성

{{>layouts/header}}
{{#article}}
<form class="container" action="" method="post">
    <div class="mb-3">
        <label class="form-label">제목</label>
        <input type="text" class="form-control" name="title" value="{{title}}">
    </div>
    <div class="mb-3">
        <label class="form-label">내용</label>
        <textarea class="form-control" rows="3" name="content">{{content}}</textarea>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
    <a href="/articles/{{article.id}}">back</a>
</form>
{{/article}}
{{>layouts/footer}}

요청 받기 - 컨트롤러, GetMapping.

@GetMapping("/articles/{id}/edit")
public String edit(@PathVariable Long id, Model model){
    //수정할 데이터를 가져오기!
    Article articleEntity = articleRepository.findById(id).orElse(null);

    //모델에 데이터를 등록
    model.addAttribute("article", articleEntity);

    //뷰 페이지 설정
    return "articles/edit";
}

 

728x90
복사했습니다!