작성한 게시글을 수정할 수 있는 기능을 구현하였다
mustache(update.mustache)
{{>layouts/header}}
<form class="container" action="/articles/up" method="post">
{{#article}}
<input type="hidden" class="form-control" name="id" value="{{id}}">
<div class="mb-3">
<label class="form-label">title</label>
<input type="text" class="form-control" name="title" value="{{title}}">
</div>
<div class="mb-3">
<label class="form-label">contents</label>
<textarea class="form-control" rows="3" name="content">{{content}}</textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a href="/articles">Back</a>
{{/article}}
</form>
{{>layouts/footer}}
Controller(TestController.java)
//수정
@GetMapping("/articles/{id}/update")
private String update(@PathVariable Long id, Model model) {
Test testEntity = testRepository.findById(id).orElse(null);
model.addAttribute("article",testEntity);
return "/articles/update";
}
@PathVariable은 Controller에서 파라미터를 받을 때 사용한다
-사용방법-
수정페이지에 변수가 잘 들어가있는 모습이다