try adding thymeleaf
This commit is contained in:
@@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,3 +5,5 @@ spring.datasource.username=postgres
|
|||||||
spring.datasource.password=password
|
spring.datasource.password=password
|
||||||
|
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
spring.thymeleaf.cache=false
|
||||||
|
spring.devtools.livereload.enabled=true
|
||||||
30
src/main/resources/templates/fragments/header.html
Normal file
30
src/main/resources/templates/fragments/header.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
...
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="#">My project</a>
|
||||||
|
</div>
|
||||||
|
<div class="navbar-collapse collapse">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li th:classappend="${module == 'index' ? 'active' : ''}">
|
||||||
|
<a href="#" th:href="@{/}">Index</a>
|
||||||
|
</li>
|
||||||
|
<li th:classappend="${module == 'paste' ? 'active' : ''}">
|
||||||
|
<a href="#" th:href="@{/paste/1wMoxOx8it}">Paste</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
10
src/main/resources/templates/index.html
Normal file
10
src/main/resources/templates/index.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org" lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Thymeleaf Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to Thymeleaf!</h1>
|
||||||
|
<p th:text="${message}">This is a message</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
src/main/resources/templates/paste.html
Normal file
13
src/main/resources/templates/paste.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org" lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Thymeleaf Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div th:replace="fragments/header :: header">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<h1>Welcome to Thymeleaf!</h1>
|
||||||
|
<p th:text="${paste.content}">This is a message</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user