Spring Boot Integration Tutorial
- Spring Boot Introduction
- Spring Boot development environment to build (Eclipse)
- Spring Boot Hello World (restful Interface) Examples
- spring boot connect Mysql
- spring boot configuration druid connection pool mysql
- Integrated spring boot mybatis (1)
- Integrated spring boot mybatis (2) - used to implement paging pagehelper
- Integrated spring boot mybatis (3) - mybatis generator arranged
- Interface package return spring boot value
- input data check spring boot (Validation)
- spring boot rest interface Integrated spring security (1) - the most simple configuration
- Interface integrated spring boot rest spring security (2) - JWT Configuration
- spring boot exception (Exception) Processing
- spring boot environment configuration (Profile) switch
- spring boot redis cache (cache) Integration
This article, we will write a hello world web application, with spring boot sole function is to access the interface return hello world string. The rear end of the front separation trend, where direct writing using java, few pages are generally written using java rear end of the interface, with the front end of the write page JS (available vue / react frame, etc.), so we choose interface mode write hello world example.
Create a project
Open Eclipse, if you have not set up a development environment, can refer spring boot build a development environment (Eclipse) to build, select the menu: File -> New -> Project...
to bring up the "New Project" dialog box, select Spring Starter Project, as shown below, click Next:
Modify some input information, click Next:
The following dialog box is used to automatically generate configuration-dependent (pom.xml), == In the dialog box, check the Web (not miss) ==, click Finish
Create a new project
Barring unforeseen circumstances, the project will create success.
Project Directory Structure
Project directory Description:
- src - the source directory
- main - Code
- java - Java code directory
- resources - resources directory profiles, etc.
- test - test code
- main - Code
- target - the compiled output directory
pom.xml file in the root directory of the project is dependent maven package configuration file.
Update dependencies
New projects, the proposed update dependencies. As shown in the left side of Eclipse directory window, the mouse pointer to the project folder, right-click pop-up menu, choose: Maven -> Update project...
pop-up dialog box check our project, to begin the update.
To view the updated schedule can be viewed in the progress window below the Eclipse interface:
write the code
Once the update is complete dependencies, add HelloController.java file. Expand the src directory, point to the directory hello right-click pop-up menu, choose: New -> File
add HelloController.java file
Add code in HelloController.java in:
package com.qikegu.hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping(value="/hello", method=RequestMethod.GET)
public String hello() {
return "Hello World!";
}
}
Code has two notes to explain:
- RestController this annotation indicates that the Control class provides an interface Restful
- This annotation map RequestMapping request url, meaning here is: is the Get method, url path / hello
Note: To further understand these two notes Restful and what is the interface, you can view the relevant information.
run
Eclipse left side of the screen to bring up the context menu item, choose: Run As -> Spring Boot App
to run the program:
Open the browser and go to: http: // localhost: 8080 / hello (spring boot is the default port 8080)