Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Spring boot Learning 1-build and easy to use

Shulou Source: shulou.com Published: 2022-06-03 06:19:35 11月23日 Update

The construction of spring boot is very simple.

First create the mavan project and create a startup class application (arbitrary class name) in the java directory, where the application file must be on the outermost layer, and spring boot will only scan the methods in the low-level files of application.

Use the SpringBootApplication annotation to identify the project startup class: Application {main (String [] args) {SpringApplication. (AccountApplication., args);}}

Then add dependencies:

Org.springframework.boot spring-boot-starter-web 1.3.5.RELEASE and controller layer: using @ Controller or @ RestController to specify controllerRestController annotations is equivalent to @ Controller+@ResponseBody. When using RestController, you only need to directly return the string to return the data to the front end. The method part still uses @ RequestMapping annotations such as @ Controller@RequestMapping (value= "/ test") public class test {@ ResponseBody @ RequestMapping (value= "/ hello"). Method = RequestMethod.GET) public String test () {System.out.print ("11111") Return "222222";}} is equivalent to @ RestController@RequestMapping (value= "/ test") public class test {@ RequestMapping (value= "/ hello", method = RequestMethod.GET) public String test () {System.out.print ("11111"); return "222222";}} the above spring boot is set up. Spring boot is embedded with tomcat. As long as you start the main method, the web end can access the methods in the project.

Tags: Method annotation project just need file front end outer layer character string effect data identity directory class name part learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux MySQL macOS Shulou Information