How to use SpringBoot to write the first Program Helloworld
How to use SpringBoot to write the first program Helloworld, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. System requirements
Java 8
Maven 3.3 +
Idea 2019 +
2.HelloWorld
Requirements: browse to send / hello request, respond to Hello,Spring Boot 2
2.1Create a maven project
2.2 introduce dependency org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE org.springframework.boot spring-boot-starter-web 2.3 to create main program / * main program class * @ SpringBootApplication: this is a SpringBoot application * / @ SpringBootApplicationpublic class MainApplication {public static void main (String [] args) {SpringApplication.run (MainApplication.class,args) Write Business @ RestControllerpublic class HelloController {@ RequestMapping ("/ hello") public String handle01 () {return "Hello, Spring Boot 2!";}}
2.5 Test
Just run the main method directly
The browser displays:
2.6 simplify configuration
Available application.properties
Server.port=8888
2.7 simplify deployment of org.springframework.boot spring-boot-maven-plugin
Package the project into a jar package and execute it directly on the target server.
Enter the folder such as target:
The cmd window executes the selected jar:
The browser displays:
Note: cancel the quick editing mode of cmd
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.