In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
SpringBoot2.x how to create a HelloWorld project, 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.
Preface
For beginners, the SSM framework often dies in configuration, and sometimes you will find that even if you follow the tutorial step by step, you will make mistakes in the end. The emergence of Springboot has solved this problem greatly. There are already a lot of tutorials or books related to Springboot.
Environment introduction
Java version: java8
Develop IDE:IDEA
Springboot version: Springboot2.4.3
Applicable version: Springboot2.x series
Maven version: maven3.6.3
OK, go.
First, create a springBoot-HelloWorld project
1. Create a new project
I created a parent-son engineering structure:
From top to bottom, we analyze them one by one:
(1) the infrastructure of Spring Boot consists of three folders:
Src/main/java: program development folder, where we write the program code.
Src/main/resources: configuration fil
Src/test/java: test program
(2) DemoApplication.java under src/main/java
The main function is to enter the main program, which is equivalent to the main function.
(3) static under src/main/resources
There are some configuration resources, such as pictures and so on.
(4) application.proties under src/main/resources
It is a global configuration file, where you define the port number of some interfaces and other information.
(5) pom file
This file is extremely important, and it defines some project dependency information.
(6) the rest is not important. Let's not talk about it here.
The project has been set up. Look at the basic case.
Second, the first SpringBoot case
Step 1: we create the Controller package under the src/main/java folder and create a new HelloWorldController class
@ RestController public class HelloWorld {@ RequestMapping ("/ hello") public String hello (String name) {return "HelloWorld!" + name;}}
Step 2: run SpringbootHelloworldApplication
@ SpringBootApplication public class SpringbootHelloworldApplication {public static void main (String [] args) {SpringApplication.run (SpringbootHelloworldApplication.class, args);}}
Step 3: access directly in the browser
OK, the first case is complete.
Third, analyze small examples
1. Pom.xml file
Give the core paragraph:
Org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test
In other words, we can add the dependencies we need under the dependencies structure in the pom file.
2. Application.properties file
After adding dependencies above, we can add some configuration to this file, for example, if our port 8080 is occupied, then the port on which we modify the project is 8888, or we change the root directory of the project to test.
Server.port=8888 server.servlet.context-path=/test
The configuration of this file is super many, here is just an example to see how to match, this properties file can also be modified to yml format.
3. Controller, service and other files
For our specific business logic, we only need to encode in the corresponding file to be the same as the SSM framework.
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.