Home >Java >javaTutorial >Chapter 1 of Getting Started with SpringBoot: Hello World

Chapter 1 of Getting Started with SpringBoot: Hello World

巴扎黑
巴扎黑Original
2017-06-26 11:14:281798browse

Preparation work:

1. Intellij IDEA (ULTIMATE version): Official website download address

2. JDK

1. Create a new project

2. Select Spring Initializr on the left panel

Enter the project name and project group Name and project ID, click to proceed to the next step

The following page is used to add dependencies. You can add dependencies according to your needs. Or you can add it in the pom.xml file. Mainly include: Core (core dependency), SQL, NOSQL

For the current test, you only need to check Web.

Click Next to complete the project creation. The project structure is as follows: (Note: Example.java was added by me)

2. Create Example.java in the corresponding directory. The code is as follows:

package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Example {
    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    @RequestMapping("/hello/{myName}")
    String index(@PathVariable String myName) {
        return "Hello "+myName+"!!!";
    }
}

3. Run the project, select SpringbootTestApplication.java, right-click--Run 'SpringbootTestApplication', or click the button as shown:

4. The program starts successfully, and the console looks as follows (part):

5. Finally, let’s test it: enter http://localhost:8080/ and http://localhost:8080/hello/王达达

Test success! ! !

Finally, the pom.xml code is also attached for reference only.

930406f08da8ee4a2ff134b688d29d1d
261ccf601aed9e706bad7e14d745ea63
   f88eb0eb1aecac9ee9b4f14c6ec6df3b4.0.064e738e3986bec0362927b9ad33d6f1a

   05a8acc5c31084a4f61ade01873802cacom.example192ca2f7b8c770b01c8f81e6bdd5b947
   9bc4cbb67f66e148869423c0d27e5f90springboot_testb68fb17cb904a46b73e6272850323873
   3d689bd3819ead35ed794427bd12f4590.0.1-SNAPSHOT83a577b3f930c490b31329be5e672d0b
   0d5281799fde01379a2f5b5ea0c57ee5jarb381c39f05d1340a5f54760f38fa259d

   8a11bc632ea32a57b3e3693c7987c420springboot_testdf406f776eecbaf16b62325323196f14
   8b55addfb40ddf4a384b1010d729e503Demo project for Spring Boota11945cc7b2902590ebb81ca9fd0b283

   58652436a08d62d32b90566dafe0913c
      05a8acc5c31084a4f61ade01873802caorg.springframework.boot192ca2f7b8c770b01c8f81e6bdd5b947
      9bc4cbb67f66e148869423c0d27e5f90spring-boot-starter-parentb68fb17cb904a46b73e6272850323873
      3d689bd3819ead35ed794427bd12f4591.5.4.RELEASE83a577b3f930c490b31329be5e672d0b
      9d08dd43193b87e544f7f9753dac4bce 8d2d71f76b067132be80f6f649e0b044
   db7b8d074c72824ed121864240fe4c81

   a01741acb88936e4cea4237317380dd9
      1c7a7393b6227ec4d47c36077ff090b8UTF-8e1707586e242e616eb540a7accd7b351
      d2d8c130ea6225f24b1c2ce2131af998UTF-837d0ee9d6f821be650562ff4d5ce07f8
      cba97bffed69576781755455c6f1e4131.837fea447ce86e32369605f68ca6046c0
   86cd8b5c0fbd401fb69261955cf13796

   fce2022be5e87c17c94245fd7ccbf1d9
      8a6cc4527fc0e71b0dfbcd757b4f1373
      b4b38e33757a6497aa8690936b905cc1
         05a8acc5c31084a4f61ade01873802caorg.springframework.boot192ca2f7b8c770b01c8f81e6bdd5b947
         9bc4cbb67f66e148869423c0d27e5f90spring-boot-starter-webb68fb17cb904a46b73e6272850323873
      09a0e22e5aaafd848ae04665be625b91

      b4b38e33757a6497aa8690936b905cc1
         05a8acc5c31084a4f61ade01873802caorg.springframework.boot192ca2f7b8c770b01c8f81e6bdd5b947
         9bc4cbb67f66e148869423c0d27e5f90spring-boot-starter-testb68fb17cb904a46b73e6272850323873
         06db57cb000bdd2564c5b32a302b10e2test03b1008234ba0cf6ad3c873aea327e8a
      09a0e22e5aaafd848ae04665be625b91
   d233ceef72c18d2307de4871b5eff5ad

   5ac54a929980b32fdd2e48b6a8da067c
      c4222ff3007372f15ec728b963e717b6
         33ca7039399a4759a8764ea38765dd46
            05a8acc5c31084a4f61ade01873802caorg.springframework.boot192ca2f7b8c770b01c8f81e6bdd5b947
            9bc4cbb67f66e148869423c0d27e5f90spring-boot-maven-pluginb68fb17cb904a46b73e6272850323873
         9424ec9162a9b85f34067d0c54f34b32
      f3567a435ac6132b26525998d793443b
   f82c24fb6fac67972f6e79c18ccef56a
1755c7176d4002e2a322de4f48c796fa

This is the first time I have come into contact with the SpringBoot architecture. Well, write it down first so as not to forget it later

The above is the detailed content of Chapter 1 of Getting Started with SpringBoot: Hello World. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn