A summary of what to do when creating a web application with Spring Boot.
Development tools: Pleiades All in One
Select New Project → Spring Starter Project. When selecting dependencies, it would be good if there were at least the following.
name | Description |
---|---|
Spring Boot DevTools | A tool that allows hot deployment when testing during development |
Thymeleaf | HTML template engine |
Spring Web Starter | What you need to create a web application |
The layout can be standardized. The version is the latest at that time.
build.gradle
dependencies {
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.4.1'
}
Add schema definition for Thymeleaf to html
tag.
layout01.html
<!DOCTYPE html>
<html
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/uikit.min.css" th:href="@{css/uikit.min.css}" />
<script src="js/uikit.min.js" th:src="@{js/uikit.min.js}"></script>
<script src="js/uikit-icons.min.js" th:src="@{js/uikit-icons.min.js}"></script>
<title>system-name</title>
</head>
<body>
<!--menu-->
<nav class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="">Top</a></li>
<li><a href=""></a></li>
</ul>
</div>
</nav>
<!--Contents-->
<div class="uk-section" layout:fragment="content">
</div>
</body>
</html>
-Add the schema definition for Thymeleaf to the html
tag.
-Specify which layout file to use.
-Add the th: remove
tag for what you are doing in the layout file, such as reading css.
index.html
<!DOCTYPE html>
<html
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layouts/layout01}">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/uikit.min.css" th:remove="all" />
<script src="js/uikit.min.js" th:remove="all"></script>
<script src="js/uikit-icons.min.js" th:remove="all"></script>
<title>top page</title>
</head>
<body>
<!--Contents-->
<div class="uk-section" layout:fragment="content">
<p>It is the top page</p>
</div>
</body>
</html>
Controller class
@Controller
public class IndexController {
@RequestMapping("/")
public String get() {
return "index.html";
}
}
Right-click on the project name → select "Run" → "Spring Boot Application".
After confirming the startup, you can access it at http: // localhost: 8080 /
.
When I try to manage the created project with Git, the bin folder and the class files in it are not ignored for some reason. So, add a setting to ignore.
For DI managed objects, you can use @Value
. defaultValue
is the default value when there is no key. Optional.
@Value("${key:defaultValue}")
private String value = null;
By default, the green leaf is an icon, so it's a good idea to disable it.
application.properties
spring.mvc.favicon.enabled=false
Recommended Posts