Introduction to Spring Boot Part 1

This article is [this blog](https://yk0807.com/techblog/2019/05/06/spring-boot%E5%85%A5%E9%96%80%E3%81%9D%E3%81 % AE1 /) is moved to Qiita. It's been a little over a month since I started using Spring Boot, and there may be some inappropriate explanations, but I would appreciate it if you could point out that.

In WEB + DB PRESS 106, there was a Spring Boot article about creating a task management service and Qiita crawl & distribution service. For the time being, I tried the task management service. The source code created by imitating the WEB + DB PRESS article this time can be found at here. We plan to make various improvements in the future. By the way, the finished product (?) Looks like this. Spring_todo.png

1. What is Spring Boot?

The Spring Framework, a Java web framework, was created in 2003, and Spring Boot was created in 2014 to make it easier to use. [DI (Dependency Injection)](https://ja.wikipedia.org/wiki/%E4%BE%9D%E5%AD%98%E6%80%A7%E3%81%AE%E6%B3 It is characterized by using the concept of% A8% E5% 85% A5).

2. What you need to develop with Spring Boot

-OpenJDK (Of course, if you develop in Java before the framework, you need it. If you want to use the current functions, you need at least 8 versions) -Spring Tool Suite (abbreviated as STS. Eclipse-based IDE. It seems that it was done in 3.9.5 for books, but as of April 2019, 4 or later It's the default, so I did it in 4.1.2) -Lombok (Read as Lombok. It is a convenient library that automatically generates getters and setters just by adding annotations. Install by simply double-clicking the downloaded lombok.jar. Will be.) -Database management system (Because it is a Web system, it is decided that it is necessary. I think that I should use the one I usually use. I used H2 Database in the book, but I did it with MySQL that I am familiar with. ) ・ Pleiades (Read as Pleiades. Eclipse Japanese localization plug-in. I don't think it is necessary for people who are good at English, but I installed it. See here for how to do this (the link is for Windows, but you can also use Mac to put the contents of the downloaded one in the features and plugins folders. It's okay).) -Maven (Read as Maven. Java build tool. If you download STS from the official page and install it, it should be okay, but install it with the brew command etc. If you do, check if it is included with mvn -version, and if not, bring it from the official page or install it with brew install maven)

3. A rough description of the Spring Boot configuration

Here, I will briefly explain the configuration of Spring Boot with a feeling like comparison with Laravel. In Spring Boot, unlike Laravel, the folder structure is not decided, so you need to think about the structure yourself. Java sources are placed under src / main / java, and non-Java (html, css, js, etc.) are placed under src / main / resources. The source for testing with JUnit is located under src / test.

src / main / java (Java source file) -Application (This is the main function. Annotate it with @SpringBootApplication. This main function is called when the project is executed. Is it close to Laravel's index.php?) -Entity (Data definition. Add @Entity annotation. Import lombok.Data and add @Data to automatically generate getters and setters. Furthermore, JPA If you add @Table (name = “table name”) using .org / wiki / Java_Persistence_API) (standard technology for handling databases in Java), a table will be created automatically. Laravel's Model (directly under app) He) + migration?) -Repository (It is for performing basic operations of CRUD (create, read, update, delete) of data defined in Entity, and is defined as an interface that inherits JpaRepository. It is a function that Laravel does not have.) -Controller (Controller that handles C of MVC, similar to that of Laravel, but implements processing for data etc. by calling Service explained below. Add @Controller annotation to class. Also, Get method Then you can map the request by annotating @GetMapping (value = ”(URL)”) in the method and @PostMapping (value = ”(URL)”) in the method in the case of Post method, so Laravel Then it may be an image close to Controller + routes) -Service (Implements the processing to be performed on the data and passes it to the Controller. This is also not in Laravel, but if you dare to say it, it may be an image that connects between the Model and the Controller. @Service annotation The actual processing is implemented by calling the CRUD operation of Repository.) -Form (a class for passing the value entered in the html form to the controller. It seems that validation is often done here. Request in Laravel?)

src / main / resources (front end, etc.) -Thymeleaf (read as time leaf. It seems to be named after the herbs of plants. So-called template engine. Blade is the default for Laravel, but Spring Boot seems to support several other template engines. ) -Application.properties (It has application setting values, and I think that the files under config are close to each other in Laravel. The database settings to be used are also set here.)

As mentioned above, I wrote it in a hurry, so it was a rough explanation, but when I write Part 2, I think I should write it in a little more detail.

Recommended Posts

Introduction to Spring Boot Part 1
Introduction to Spring Boot ② ~ AOP ~
[Introduction to Spring Boot] Form validation check
An introduction to Spring Boot + in-memory data grid
[Introduction to Spring Boot] Authentication function with Spring Security
Introduction to Ratpack (7) --Guice & Spring
[Introduction to Spring Boot] Submit a form using thymeleaf
Introduction to Linux Container / Docker (Part 1)
Introduction to Linux Container / Docker (Part 2)
How to use ModelMapper (Spring boot)
Upgrade spring boot from 1.5 series to 2.0 series
Spring Boot starting from zero Part 2
Spring Boot starting from zero Part 1
The story of raising Spring Boot from 1.5 series to 2.1 series part2
Introduction to Ruby 2
Introduction to Spring Boot x OpenAPI ~ OpenAPI made with Generation gap pattern ~
Spring Fox ① Introduction
Introduction to swift practice output Chapter 5 Part 2
Introduction to SWING
Challenge Spring Boot
Introduction to web3j
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Introduction to Micronaut 1 ~ Introduction ~
[Java] Introduction to Java
Introduction to migration
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
Spring Boot Form
Introduction to java
Spring Boot Memorandum
gae + spring boot
Introduction to Doma
How to split Spring Boot message file
Add spring boot and gradle to eclipse
Introduction to Java development environment & Spring Boot application created with VS Code
JSUG Study Group 2018 Part 4 Spring 5 & Spring Boot 2 Hands-on Impressions
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
How to make Spring Boot Docker Image smaller
Road to Java Engineer Part1 Introduction & Environment Construction
The story of raising Spring Boot 1.5 series to 2.1 series
Try to implement login function with Spring Boot
How to add a classpath in Spring Boot
How to bind to property file in Spring Boot
Try to automate migration with Spring Boot Flyway
[Java] Article to add validation with Spring Boot 2.3.1.
I wanted to gradle spring boot with multi-project
Apply Twitter Bootstrap 4 to Spring Boot 2 using Webjars
[Spring Boot] How to refer to the property file
Spring Boot --How to set session timeout time
SPRING BOOT learning record 01
Introduction to JAR files
Spring Boot + Heroku Postgres
Introduction of Docker --Part 1--
Introduction to Ratpack (8)-Session
Introduction to RSpec 1. Test, RSpec
Spring boot memo writing (1)
Introduction to bit operation
Introduction to Ratpack (6) --Promise
Introduction to Ratpack (9) --Thymeleaf
First Spring Boot (DI)
SPRING BOOT learning record 02