Spring boot first experience

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/liu_Yudong/article/details/89500792

Spring boot first experience

The first Spring boot record of the development of simple
tools: intellij idea
environment; JDK1.8

  1. New Spring boot Project
    File -> New -> Project - > Spring Initializr
    Here Insert Picture Description

  2. Code Description:

    DennyApplication.java

    Automatically generated when you create a project, is Spring boot startup file

    HelloWorldController.java

    Defined from the control layer, to generate web

    pom.xml

    Key configuration files

  3. Develop

Configuration pom.xml

Configure the web

<dependency>
     <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Configuration test test

 <dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-test</artifactId>
	    <scope>test</scope>
</dependency>

Edit Controller layer

The most simple HelloWorld

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public String index(){
        return "Hello World";
    }
}

Description:
  @RestController = @ + @ responseBody the Controller; return json data format
  @RequestMapping defined routing

Start Spring boot

Run directly DennyApplication.java file, if given, to see if 8080 port is occupied
in the browser input http: // localhost: 8080 + routing your own definition, the results come out.

Guess you like

Origin blog.csdn.net/liu_Yudong/article/details/89500792