Welcome
Welcome at the course of the Spring Boot Training
Below you find the content with links to the different parts of this course
News Flash
-
Released version v1.3.0
Release notes
-
Add topic: Add Authorities for having the authorization based on Authority
-
Add first steps for Security using the real DB using BCrypt and DaoAuthenticationProvider (without Authority yet)
-
Some improvements after doing the assignments myself regarding Security
-
Fix role name from BIRDS to API
-
Add topic: 4 (four) levels of query syntax
-
Create better indexing
-
Move logging intro from additional.adoc ⇒ introduction.adoc
Monitoring and Logging
Miscellaneous
Topic: Mustache
What you will learn
-
Why you will want to use Mustache
-
What Mustache is
-
How to implement Mustache
Why: Mustache
Mustache makes it easy to have multiple pages (HTML files) using some shared parts (the head section and the footer are the same)
What: Mustache
Mustache is a template engine
How: Mustache
-
Templates files live in src/main/resources/templates
-
Template files have the extension .mustache
-
{{>header}}
-
{{>footer}}
Standard html files still are still reachable in src/main/resources/static |
Previously the names of the Mustache files had the .html suffix. If you read that on some Internet post you are reading and old post < 2019. |
Steps: How: Mustache
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>:: My great website ::</title>
</head>
<body>
Remember that this file will be written only once. Remember that you can use this file now everywhere using the Mustache syntax {{>header}} |
<script src="js/index.js"></script>
</body>
</html>
Remember that this file will be written only once. Remember that you can use this file now everywhere using the Mustache syntax {{>footer}} |
{{>header}}
<div>
and some more standard html
</div>
{{>footer}}
{{>header}}
<div>
and some more standard html
</div>
{{>footer}}
{{>header}}
<div>
and some more standard html
</div>
{{>footer}}
@Controller
public class HomeController {
@GetMapping
public String getHome(){
return "index";
}
@GetMapping("guests")
public String getGuests(){
return "guests"; // now guests.mustache file is used
}
@GetMapping("tables")
public String getGuests(){
return "tables"; // now tables.mustache file is used
}
}
-
This class maps "" to the view index.mustache
-
This class maps guests to the view guests.mustache
-
This class maps tables to the view tables.mustache
You are mandatory to write a Controller when using Mustache. Without a Controller, Mustache will not work!!! |
Assignment: Mustache
To get started with Mustache template engine
During this assignment you will refactor your profile page using standard html to a Mustache enabled web application
Add Mustache template engine using the description above to your application.
-
Your page(s) only contain ONE header and footer
-
Your page(s) may (and should) contain different bodies for the real content of that page
-
After adding Mustache your profile site is still showing the same content as before.
Using Mustache you only have to write one head and one footer for all the pages you have in your web-application