From 59da25207e8f9fe5a2c24e6c6d4e89dc92107824 Mon Sep 17 00:00:00 2001 From: luxic Date: Mon, 18 Aug 2025 08:50:08 +0700 Subject: [PATCH] try adding thymeleaf --- .../pastebin/controller/HomeController.java | 32 +++++++++++++++++++ src/main/resources/application.properties | 4 ++- .../resources/templates/fragments/header.html | 30 +++++++++++++++++ src/main/resources/templates/index.html | 10 ++++++ src/main/resources/templates/paste.html | 13 ++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/id/my/luxic/pastebin/controller/HomeController.java create mode 100644 src/main/resources/templates/fragments/header.html create mode 100644 src/main/resources/templates/index.html create mode 100644 src/main/resources/templates/paste.html diff --git a/src/main/java/id/my/luxic/pastebin/controller/HomeController.java b/src/main/java/id/my/luxic/pastebin/controller/HomeController.java new file mode 100644 index 0000000..ee179ec --- /dev/null +++ b/src/main/java/id/my/luxic/pastebin/controller/HomeController.java @@ -0,0 +1,32 @@ +package id.my.luxic.pastebin.controller; + +import id.my.luxic.pastebin.model.Paste; +import id.my.luxic.pastebin.service.PasteService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@Controller +public class HomeController { + + private final PasteService service; + + public HomeController(PasteService service) { + this.service = service; + } + + @GetMapping("/") + public String home(Model model) { + model.addAttribute("message", "Hello, Thymeleaf!"); + return "index"; + } + + @GetMapping("/paste/{id}") + public String paste(Model model, @PathVariable String id) { + Paste paste = service.findById(id); + model.addAttribute("paste", paste); + return "paste"; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d11cc43..ae31c10 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,4 +4,6 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/pastebin spring.datasource.username=postgres spring.datasource.password=password -spring.jpa.hibernate.ddl-auto=update \ No newline at end of file +spring.jpa.hibernate.ddl-auto=update +spring.thymeleaf.cache=false +spring.devtools.livereload.enabled=true \ No newline at end of file diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html new file mode 100644 index 0000000..14fed38 --- /dev/null +++ b/src/main/resources/templates/fragments/header.html @@ -0,0 +1,30 @@ + + + + ... + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..8193874 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,10 @@ + + + + Thymeleaf Example + + +

Welcome to Thymeleaf!

+

This is a message

+ + \ No newline at end of file diff --git a/src/main/resources/templates/paste.html b/src/main/resources/templates/paste.html new file mode 100644 index 0000000..74c7444 --- /dev/null +++ b/src/main/resources/templates/paste.html @@ -0,0 +1,13 @@ + + + + Thymeleaf Example + + +
+ +
+

Welcome to Thymeleaf!

+

This is a message

+ + \ No newline at end of file