preamble
Generally speaking, it's a good idea to useIDEA Creating SpringBoot ProjectsThere are two ways. One is the official Spring website provides a quick generation of SpringBoot project site, you can download the official website directly, and then imported into IDEA. The other is to directly use IDEA to create a SpringBoot project, general development is also used in this way to create. Although SpringBoot simplifies the configuration of Spring, but before learning Spring basics need to have a certain mastery.
I. Website way to create
1, first of all, open Spring's official website, under the Projects guide bar to find SpringBoot
2, found that the official website of the SpringBoot version has reached 2.6.6, about its description and functionality can also go to look carefully, find the bottom of theSpring InitializrClick to enter
3, after entering the relevant configurations according to their own needs, configured to download the appropriate jar can be, and then imported into the IDEA inside can be
4, after importing IDEA, the irrelevant packages will be deleted, you will find that the project structure is no different from the previous one.
5, write a Controller class for testing, because SpringBoot embeddedTomcatserver , so there is no need to configure Tomcat. @RestController annotation , equivalent to the combination of @Controller + @ResponseBody two annotations , the return of json data do not need to be in front of the method to add @ResponseBody annotation . @Controller means jumping to the page , @RestController does not jump to the page , directly return content .
package ;
import ;
import ;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
//Calling Operations,Receive front-end parameters
return "hello,world";
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
6. Presentation of results
Second, IDEA way to create
1, File-> New Poject-> Spring Initializr, found that the source is still the same site, configure it and click Next!
2. Add relevant dependencies
3, delete some irrelevant files, you can complete the creation of SpringBoot project
4, start the project, you will find the familiar Tomcat and http request port 8080
Note: Start SpringBoot, banner can be customized, created under the Resource file, and then put your favorite pattern can be started Banner online generation tool URL (in which you can define your favorite pattern):Spring Boot banner online generation tool, production and download, modify the replacement text to achieve customized, personalized boot
5, the default port number is 8080, we can modify the port number in the configuration file
=8081
- 1
6, write a Controller class for testing , if you only write @Controller, do not write @ResponseBody, there will be unable to parse the MVC view of the prompt. If you want to return content directly, either @Controller + @ResponseBody, or @RestController
package ;
import ;
import ;
import ;
@Controller//RestControllerReturns the entity object,ControllerBack to page
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hello,SpringBoot!";
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
7. Display of results