[Spring Boot] Web application creation

Introduction

A summary of what to do when creating a web application with Spring Boot.

Prerequisites

Development tools: Pleiades All in One

Preparation

Project creation

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

Added Thymeleaf Layout Dialect as a dependency

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'
}

First screen creation

HTML creation for layout

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>

Individual HTML creation

-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 creation

Controller class


@Controller
public class IndexController {

	@RequestMapping("/")
	public String get() {
		return "index.html";
	}

}

Application launch

Right-click on the project name → select "Run" → "Spring Boot Application". After confirming the startup, you can access it at http: // localhost: 8080 /.

Source control

Ignore bin folder

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.

Use of property file values

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; 

Disable favicon

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

[Spring Boot] Web application creation
Inquiry application creation with Spring Boot
Start web application development with Spring Boot
Spring Boot 2.3 Application Availability
Run WEB application with Spring Boot + Thymeleaf
CICS-Run Java application-(4) Spring Boot application
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Spring Boot application development in Eclipse
Spring Boot application code review points
Implement Spring Boot application in Gradle
Web application creation with Nodejs with Docker
Sample web application that handles multiple databases in Spring Boot 1.5
Processing at application startup with Spring Boot
Let's make a book management web application with Spring Boot part1
Personal application creation # 2
Let's make a book management web application with Spring Boot part3
Personal application creation # 3
Personal application creation # 1
Let's make a book management web application with Spring Boot part2
Challenge Spring Boot
Launch Nginx + Spring Boot application with docker-compose
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
Memorandum (Spring Web)
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
Java beginner tried to make a simple web application using Spring Boot
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
Deploy the WEB application by Spring Boot to Tomcat server as WAR
Spring5 MVC Web application development with Visual Studio Code Maven template creation
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Configure Spring Boot application with maven multi module
Basic Web application creation Servlet / JSP (login function)
Create a Spring Boot application using IntelliJ IDEA
Basic Web application creation Servlet / JSP (posting screen)
Deploy a Spring Boot application on Elastic Beanstalk
Create a web api server with spring boot
Basic Web application creation Servlet / JSP (logout function)
Personal application creation term
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Sign in to a Spring Boot web application on the Microsoft ID platform
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 2/3 [Page creation 1/2]
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 3/3 [Page creation 2/2]
Learning Spring Boot [Beginning]
Web application test automation
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
I tried to clone a web application full of bugs with Spring Boot
Spring boot tutorials Topics
Download with Spring Boot
Spring Boot application built-in Tomcat, Apache and WebSocket integration