Java beginner tried to make a simple web application using Spring Boot

Introduction

――For various reasons, I am studying Spring Boot. ――I don't remember Java itself, Servlets, JSPs, etc. too long ago. So it will be a beginner start. ――I was able to make a simple SPA in about 16 hours in total, while fitting it securely in each step. ――There is no special design.

Execution environment

# OS/software/Library version
1 Mac OS X EI Capitan
2 Java 1.8.0_111
3 Tomcat 8.0.43
4 MySQL 5.6.38

Development environment

# OS/software/Library version
1 Eclipse 4.5 Mars
2 Gradle 4.4.1

Application environment

# OS/software/Library version
1 Spring Boot 1.5.9
2 JPA(Java Persistence API)
3 Thymeleaf

Various installations from Homebrew

Update brew

brew update && brew upgrade && brew cleanup

Java

Installation

brew cask install java

PATH setting

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Tomcat

Installation

brew install tomcat

Gradle

Installation

brew install gradle

Eclipse installation

Download Mars

https://www.eclipse.org/downloads/packages/release/Mars/2

Installation

Place Eclipse.app under / Applications.

Download various plug-ins

** Japanese localization plug-in ** http://mergedoc.osdn.jp/#pleiades.html

JStyle http://mergedoc.osdn.jp/#jstyle.html

Localizing into Japanese

Place the jp.sourceforge.mergedoc.pleiades directory of the unzipped plugin under /Applications/Eclipse.app/Contents/Eclipse/plugins/.

Open /Applications/Eclipse.app/Contents/Eclipse/eclipse.ini and add the writing.

-Xverify:none
-javaagent:/Applications/Eclipse.app/Contents/Eclipse/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar

JStyle

Place the unzipped plugin jar under /Applications/Eclipse.app/Contents/Eclipse/plugins/.

Initial setup of Eclipse

After starting, open the environment settings at the top left of the screen.

--From "Java> Compiler", change the Java version to 1.8. --Add Java SE 8 from "Java> Installed JRE". --Adjust the "General> JStyle" settings. --Set "General> Web Browser". --If proxy settings are required, set "General> Network Connection".

Tomcat connection settings

After startup, open "Server> Runtime Environment" from the environment settings at the top left of the screen.

  1. Select "Apache> Apache Tomcat v8.0" from Add and proceed.
  2. Enter the name and Tomcat installation directory. The directory is as follows.
/usr/local/Cellar/[email protected]/8.0.43/libexec

Install Spring and Gradle plugins

STS installation

  1. Open Help> Eclipse Marketplace at the top of the screen.
  2. Enter STS in the search window to install.

Install Gradle plugin

  1. Open Help> Eclipse Marketplace at the top of the screen.
  2. Enter Gradle in the search window to install.

Creating a Spring Boot project

  1. Open "File> New> Create Spring Starter Project" at the top of the screen.
  2. Enter the project name and check the box below to complete.

springjpa2015051101.png

Tomcat startup port and database connection settings

-Edit /projectname/src/main/resources/application.properties.

//Tomcat startup port
server.port=18080

//Database connection settings
spring.datasource.url=jdbc:mysql://localhost:3306/{Database name}
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Creating an application

――This time, I created the following functions.

# Function name
1 List user information
2 Partial match search for user name and group name
3 Display user information
4 Username update

--Users have attributes such as groups to form a join relationship.

Creating databases and tables

CREATE DATABASE {Database name} DEFAULT CHARACTER SET utf8;

CREATE TABLE `groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `group_id` int(11) NOT NULL,
  `name` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

Input of initial data

INSERT INTO `groups` VALUES (1,'admin'),(2,'sales');
INSERT INTO `users` VALUES (1,1,'Tanaka'),(2,2,'Takahashi'),(3,2,'Suzuki');

Implementation

--I learned from Domain Driven (DDD) and constructed the class, but please understand that it may contain some code that is not so good. --The actual source code.

Source code

https://github.com/neriai/spring-boot-sandbox

Run

Run application

Select the project, right-click and click Run> Spring Boot Application.

demo

demo.gif

Summary

――It was more likely to fit in JPA, Thymeleaf or other libraries than in Java or Spring Boot. --Gradle Easy to use. --The area around Entity fits. --It is recommended to set it as a shortcut for running or stopping the application in Eclipse.

Recommended Posts

Java beginner tried to make a simple web application using Spring Boot
I tried to make a simple face recognition Android application using OpenCV
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
I tried to make a talk application in Java using AI "A3RT"
I tried to clone a web application full of bugs with Spring Boot
[Beginner] Try to make a simple RPG game with Java ①
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
I tried to build a simple application using Dockder + Rails Scaffold
java I tried to break a simple block
Create a Spring Boot application using IntelliJ IDEA
Steps to create a simple camel app using Apache Camel Spring Boot starters
Sign in to a Spring Boot web application on the Microsoft ID platform
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
Create a portfolio app using Java and Spring Boot
I tried to make a login function in Java
[Introduction to Spring Boot] Submit a form using thymeleaf
[Spring Boot] Web application creation
CICS-Run Java application-(4) Spring Boot application
Make a rhombus using Java
A story that stumbled when deploying a web application created with Spring Boot to EC2
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
I tried to modernize a Java EE application with OpenShift.
[Java] Deploy the Spring Boot application to Azure App Service
Let's make a simple API with EC2 + RDS + Spring boot ①
I tried using Hotwire to make Rails 6.1 scaffold a SPA
I tried to implement a buggy web application in Kotlin
I tried to make a client of RESAS-API in Java
Introducing Spring Boot2, a Java framework for web development (for beginners)
I tried to get started with Swagger using Spring Boot
I made a simple MVC sample system using Spring Boot
Try to make a simple callback
How to make a Java container
How to make a Java array
Implement a simple Web REST API server with Spring Boot + MySQL
I tried Spring Boot introductory guide [Building a RESTful Web Service]
Minimal configuration to run Spring Boot application on Azure Web Apps
[Unity] I tried to make a native plug-in UniNWPathMonitor using NWPathMonitor
Automatically deploy a Web application developed in Java using Jenkins [Preparation]
I tried to make an Android application with MVC now (Java)
[Java] I tried to make a maze by the digging method ♪
Spring Boot Introductory Guide I tried [Consuming a RESTful Web Service]
How to make a groundbreaking diamond using Java for statement wwww
I want to develop a web application!
Try using Java framework Nablarch [Web application]
How to make a Java calendar Summary
Create a simple web application with Dropwizard
How to make a Discord bot (Java)
Start web application development with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
[iOS] I tried to make a processing application like Instagram with Swift
Deploy the WEB application by Spring Boot to Tomcat server as WAR
Volume of trying to create a Java Web application on Windows Server 2016
Introduction to Java development environment & Spring Boot application created with VS Code
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I tried to make Basic authentication with Java
Create a simple search app with Spring Boot
Connect to Aurora (MySQL) from a Java application
I did Java to make (a == 1 && a == 2 && a == 3) always true
How to make Spring Boot Docker Image smaller