From c0b7dc928a460ecf17b10a431f42d097cdad3d9a Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Wed, 18 Nov 2020 13:18:52 +0100 Subject: [PATCH 1/5] BAEL-4225 Thymeleaf Variables --- .../baeldung/thymeleaf/articles/Article.java | 28 +++++++++++++ .../articles/ArticlesController.java | 37 ++++++++++++++++++ .../templates/articles/articles-list.html | 39 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java create mode 100644 spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java create mode 100644 spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java new file mode 100644 index 0000000000..9b01328e45 --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java @@ -0,0 +1,28 @@ +package main.java.com.baeldung.thymeleaf.articles; + +public class Article { + + private String name; + private String url; + + public Article(String name, String url) { + this.name = name; + this.url = url; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java new file mode 100644 index 0000000000..401ef30156 --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -0,0 +1,37 @@ +package main.java.com.baeldung.thymeleaf.articles; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.Arrays; +import java.util.List; + +@Controller +@RequestMapping("/api/articles") +public class ArticlesController { + + @GetMapping + public String allArticles(Model model) { + model.addAttribute("articles", fetchArticles()); + return "articles/articles-list"; + } + + private List
fetchArticles() { + return Arrays.asList( + new Article( + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" + ), + new Article( + "Spring MVC Data and Thymeleaf", + "https://www.baeldung.com/spring-mvc-thymeleaf-data" + ) + ); + } +} diff --git a/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html b/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html new file mode 100644 index 0000000000..de03a86731 --- /dev/null +++ b/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html @@ -0,0 +1,39 @@ + + + + Thymeleaf Variables + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+

+
+ +
+
+ +
+
+
+ + \ No newline at end of file From 5b591b27b9057b6f194b65adc02be7ad6ec3b39e Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:39:42 +0100 Subject: [PATCH 2/5] BAEL-4225 Thymeleaf Variables --- .../articles/ArticlesController.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 401ef30156..e7c7e9b18d 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -20,18 +20,18 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( - new Article( - "Introduction to Using Thymeleaf in Spring", - "https://www.baeldung.com/thymeleaf-in-spring-mvc" - ), - new Article( - "Spring Boot CRUD Application with Thymeleaf", - "https://www.baeldung.com/spring-boot-crud-thymeleaf" - ), - new Article( - "Spring MVC Data and Thymeleaf", - "https://www.baeldung.com/spring-mvc-thymeleaf-data" - ) + new Article( + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" + ), + new Article( + "Spring MVC Data and Thymeleaf", + "https://www.baeldung.com/spring-mvc-thymeleaf-data" + ) ); } } From 6c88ec6a6c6a2c3830b08964e59ffb7849dbbcec Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:40:43 +0100 Subject: [PATCH 3/5] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index e7c7e9b18d..9db994bbf2 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -21,7 +21,7 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( new Article( - "Introduction to Using Thymeleaf in Spring", + "Introduction to Using Thymeleaf in Spring", "https://www.baeldung.com/thymeleaf-in-spring-mvc" ), new Article( From a329743e7bf2e2b8b7a7aed754a9815244c7fba3 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:41:01 +0100 Subject: [PATCH 4/5] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 9db994bbf2..3274c79222 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -24,9 +24,9 @@ public class ArticlesController { "Introduction to Using Thymeleaf in Spring", "https://www.baeldung.com/thymeleaf-in-spring-mvc" ), - new Article( - "Spring Boot CRUD Application with Thymeleaf", - "https://www.baeldung.com/spring-boot-crud-thymeleaf" + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" ), new Article( "Spring MVC Data and Thymeleaf", From e2239b4c6dba3d71a540ceb8241964338d937c32 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:41:50 +0100 Subject: [PATCH 5/5] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 3274c79222..cfbf0fcaa6 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -21,9 +21,9 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( new Article( - "Introduction to Using Thymeleaf in Spring", - "https://www.baeldung.com/thymeleaf-in-spring-mvc" - ), + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), new Article( "Spring Boot CRUD Application with Thymeleaf", "https://www.baeldung.com/spring-boot-crud-thymeleaf"