From 8fda1e5a750a098fd9b03b10e78d9377aa96633d Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 16 Jan 2020 10:16:23 +0100 Subject: [PATCH] Separated layout from content with Thymeleaf --- src/main/java/de/juplo/demo/HtmlController.java | 2 +- src/main/resources/templates/home.html | 13 +++++++++++++ src/main/resources/templates/layout.html | 12 +++++------- src/test/java/de/juplo/demo/HtmlControllerTest.java | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/templates/home.html diff --git a/src/main/java/de/juplo/demo/HtmlController.java b/src/main/java/de/juplo/demo/HtmlController.java index eaa2fcc..5696718 100644 --- a/src/main/java/de/juplo/demo/HtmlController.java +++ b/src/main/java/de/juplo/demo/HtmlController.java @@ -27,6 +27,6 @@ public class HtmlController public String fetch(Model model, @RequestParam String path) { model.addAttribute("text", service.getRemoteText(path)); - return "layout"; + return "home"; } } diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html new file mode 100644 index 0000000..6076f98 --- /dev/null +++ b/src/main/resources/templates/home.html @@ -0,0 +1,13 @@ + + + + + Shows Remote-Content + + +

Fetched Data

+
+
TEXT
+
+ + diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html index bc5799a..233b937 100644 --- a/src/main/resources/templates/layout.html +++ b/src/main/resources/templates/layout.html @@ -1,9 +1,9 @@ - + - Shows Remote-Content + TITLE @@ -11,11 +11,9 @@
-
-

Information About Fetched Data

-
-

TEXT

-
+
+

HEADER

+
BODY
diff --git a/src/test/java/de/juplo/demo/HtmlControllerTest.java b/src/test/java/de/juplo/demo/HtmlControllerTest.java index ceb14e4..1cf7274 100644 --- a/src/test/java/de/juplo/demo/HtmlControllerTest.java +++ b/src/test/java/de/juplo/demo/HtmlControllerTest.java @@ -47,7 +47,7 @@ public class HtmlControllerTest String result = controller.fetch(model, "foo"); - assertThat(result).isEqualTo("layout"); + assertThat(result).isEqualTo("home"); ArgumentCaptor> captor = ArgumentCaptor.forClass(Mono.class); verify(model).addAttribute(eq("text"), captor.capture()); StepVerifier -- 2.20.1