Kr Younger 6 anni fa
parent
commit
55effa6bbe

+ 1
- 1
README.md Vedi File

@@ -4,7 +4,7 @@ Build a simple blog app using spring and database. This uses Thymeleaf and Boots
4 4
 The overall architecture looks like this:
5 5
 ![web arch](./Weblogg.png)
6 6
 
7
-Use web pages for it.
7
+Uses web pages for it.
8 8
 
9 9
 This db is currently Postgres. The Mysql config is slightly different.
10 10
 

+ 2
- 2
src/main/java/rocks/zipcode/weblogg/controller/HomeController.java Vedi File

@@ -15,12 +15,12 @@ public class HomeController {
15 15
     @Autowired
16 16
     PostController postController;
17 17
 
18
-@RequestMapping("/")
18
+    @RequestMapping("/")
19 19
     public String index() {
20 20
         return "index";
21 21
     }
22 22
 
23
-@RequestMapping(value = "/list", method = RequestMethod.GET)
23
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
24 24
     public String postList(Model model) {
25 25
         List<Post> posts = postController.listAll();
26 26
         model.addAttribute("posts", posts);

+ 1
- 4
src/main/java/rocks/zipcode/weblogg/model/AuditModel.java Vedi File

@@ -11,10 +11,7 @@ import java.util.Date;
11 11
 
12 12
 @MappedSuperclass
13 13
 @EntityListeners(AuditingEntityListener.class)
14
-@JsonIgnoreProperties(
15
-        value = {"createdAt", "updatedAt"},
16
-        allowGetters = true
17
-)
14
+@JsonIgnoreProperties(value = { "createdAt", "updatedAt" }, allowGetters = true)
18 15
 public abstract class AuditModel implements Serializable {
19 16
     private static final long serialVersionUID = -9183951012406250484L;
20 17
 

+ 2
- 0
src/main/java/rocks/zipcode/weblogg/model/Comment.java Vedi File

@@ -28,6 +28,8 @@ public class Comment extends AuditModel {
28 28
     @JsonIgnore
29 29
     private Post post;
30 30
 
31
+    public Comment() {}
32
+
31 33
     public Long getId() {
32 34
         return this.id;
33 35
     }

+ 5
- 6
src/main/java/rocks/zipcode/weblogg/model/Post.java Vedi File

@@ -11,8 +11,8 @@ public class Post extends AuditModel {
11 11
     private static final String ID2 = "id";
12 12
 
13 13
     @Id
14
-    @GeneratedValue(strategy = GenerationType.SEQUENCE) //GenerationType.IDENTITY)
15
-    //@Column(name = ID2, updatable = false, nullable = false)
14
+    @GeneratedValue(strategy = GenerationType.SEQUENCE) // GenerationType.IDENTITY)
15
+    // @Column(name = ID2, updatable = false, nullable = false)
16 16
     private Long id;
17 17
 
18 18
     @NotNull
@@ -28,8 +28,9 @@ public class Post extends AuditModel {
28 28
     @Lob
29 29
     private String content;
30 30
 
31
-    public Post() {}
32
-    
31
+    public Post() {
32
+    }
33
+
33 34
     public Post(String title, String content) {
34 35
         this.title = title;
35 36
         this.content = content;
@@ -68,6 +69,4 @@ public class Post extends AuditModel {
68 69
         this.content = content;
69 70
     }
70 71
 
71
-    // Getters and Setters (Omitted for brevity)
72
-
73 72
 }

+ 10
- 6
src/main/resources/templates/index.html Vedi File

@@ -5,7 +5,8 @@
5 5
     <meta charset="UTF-8" />
6 6
     <title>Blog</title>
7 7
 
8
-    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
8
+    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
9
+        crossorigin="anonymous">
9 10
 
10 11
 </head>
11 12
 
@@ -13,10 +14,13 @@
13 14
     <div class="container">
14 15
         <div class="jumbotron">
15 16
             <h1>Welcome to Weblogg!</h1>
16
-     
17
-            <p>    Now is: <b th:text="${execInfo.now.time}"></b>
18
-            </p>
17
+
18
+            <p>A very simple blog app.</p>
19
+
20
+            <p><a href="/list" class="btn btn-primary">Show Posts...</a></p>
21
+
19 22
         </div>
20
-    </div></body>
23
+    </div>
24
+</body>
21 25
 
22
-</html>
26
+</html>

+ 14
- 9
src/main/resources/templates/list.html Vedi File

@@ -5,7 +5,8 @@
5 5
     <meta charset="UTF-8" />
6 6
     <title>Blog</title>
7 7
 
8
-    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
8
+    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
9
+        crossorigin="anonymous">
9 10
 
10 11
 </head>
11 12
 
@@ -15,26 +16,30 @@
15 16
             <h1>Welcome to Weblogg!</h1>
16 17
             <h3>Posts</h3>
17 18
             <div th:each="post : ${posts}">
18
-            <div class="card" style="width: 18rem;">
19
-                <div class="card-body">
20
-                  <h5 class="card-title" th:text="${post.title}"></h5>
21
-                  <p class="card-text" th:text="${post.content}"></p>
22
-                  <a href="#" class="btn btn-primary">Details...</a>
19
+                <div class="card" style="width: 80%;">
20
+                    <div class="card-body">
21
+                        <h5 class="card-title" th:text="${post.title}"></h5>
22
+                        <p class="card-text" th:text="${post.content}"></p>
23
+                        <p><a href="#" class="btn btn-primary">Details...</a>&nbsp;
24
+                            <small><small><span style="float: right" th:text="${post.createdAt}"></span></small></small></p>
25
+                    </div>
23 26
                 </div>
24
-              </div>
25 27
             </div>
26 28
             <h3>A Table of the Posts</h3>
27 29
             <table class="table table-striped">
28 30
                 <tr>
31
+                    <th>Id</th>
29 32
                     <th>Title</th>
30 33
                     <th>Content</th>
31 34
                 </tr>
32 35
                 <tr th:each="post : ${posts}">
36
+                    <td th:text="${post.id}"></td>
33 37
                     <td th:text="${post.title}"></td>
34 38
                     <td th:text="${post.content}"></td>
35 39
                 </tr>
36 40
             </table>
37 41
         </div>
38
-    </div></body>
42
+    </div>
43
+</body>
39 44
 
40
-</html>
45
+</html>