In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article to share with you is about the springboot project rapid construction steps is what kind of, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.
1. problem description
Springboot's appearance has become a great boon for Java developers, greatly improving the efficiency of development. In fact, springboot is only based on maven, and the existing maven gav is encapsulated. Today, springboot is quickly introduced with the simplest code.
2. solutions
We strongly recommend that you use the paid version of Idea (cracking thanks to Lanyu), Idea for maven, git and other plug-ins support better.
Use the spring Initializr that comes with idea (the actual call is the initializr on the official website of springboot) to quickly create a new springboot project.
2.1 New Springboot Project
(1)file->new->project
(2) Click next (first)
Create a springboot project (because of the connection to foreign websites, next sometimes delays a few seconds), change two values to your own configuration, Group: com.laowang, Artifact:sptest, others can be left alone, click ok
(3) Click next (second)
Select web-> spring web starter
(4) Click next (third)
No need to modify, finish directly
The new springboot project has been completed.
2.2 Springboot generates three files by default
Three files generated by default
2.2.1. pom.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.4.RELEASE com.laowang sptest 0.0.1-SNAPSHOT sptest Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
Focus on one gav: spring-boot-starter-web, others can be deleted.
2.2.2 application.properties
This file is empty by default. The default boot port number of springboot is 8080, which can be modified in the file.
2.2.3 Startup class file (SptestApplication.java)
package com.laowang.sptest;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SptestApplication { public static void main(String[] args) { SpringApplication.run(SptestApplication.class, args); }}
The key is the tag: @SpringBootApplication
2.3 Verify springboot
Create a new ctroller package under com.laowang.sptest and create a new class: HelloController
package com.laowang.sptest.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;@Controllerpublic class HelloController { @RequestMapping("/") @ResponseBody public String getHello() { return "hello"; }}
Execution effect:
The service starts normally.
2.4 highlights
Two points need to be made:
(1) Class files should be placed at the same level or under the next directory as the startup class. This project is under the com.laowang.sptest package. Because springboot scans and loads label classes (@RestController,@Service,@Configuraion,@Component, etc.) of the same level or lower level directory of the startup class by default, if you really need to load label classes of other directories, you can scan and load by configuring the label @ComponentScan(specific package) on the startup.
(2) The resource file is placed under resources by default, and templates is placed under dynamic files by default, such as html files, but it should be used with thymeleaf (new gav is required in pom files).
There is nothing else, springboot is mainly through the multiple starters provided by spring and some default conventions, to achieve rapid construction of the project.
The above is how the steps of the rapid construction of the springboot project are. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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: 262
*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.