File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,12 @@ public String createPost(Post post) {
3232 }
3333
3434 @ GetMapping ("/posts/{postId}" )
35- public String showPost () {
35+ public String showPost (@ PathVariable ("postId" ) long id , Model model ) {
36+ Post post = postRepository .findById (id )
37+ .orElseThrow (() -> new IllegalArgumentException ("Invalid Post Id:" + id ));
38+
39+ model .addAttribute ("post" , post );
40+
3641 return "blog/show" ;
3742 }
3843
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ <h1>Blog</h1>
99 </ dt >
1010
1111 < dd >
12- < span th:text =" ${post.content} " > Content </ span >
12+ < a th:href =" @{/posts/{id}(id= ${post.id})} " > Show </ a >
1313 < a th:href ="@{/posts/{id}/edit(id=${post.id})} "> Edit</ a >
1414 </ dd >
1515</ dl >
Original file line number Diff line number Diff line change 1- < p > Post title</ p >
1+ <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
2+ < html xmlns ="http://www.w3.org/1999/xhtml " xmlns:th ="http://www.thymeleaf.org ">
3+
4+ < body >
5+ < h1 th:text ="${post.title} "> </ h1 >
6+ < hr >
7+ < p th:text ="${post.content} "> </ p >
8+
9+ < p > < a th:href ="@{/posts/{id}/edit(id=${post.id})} "> Edit</ a > </ p >
10+ < hr >
11+ < a th:href ="@{/posts} "> Go back to posts</ a >
12+ </ body >
13+ </ html >
You can’t perform that action at this time.
0 commit comments