SpringBoot-IDEA 快速入门

一  快速入门

1maven构建项目

SpringBoot-IDEA 快速入门

2 点 Next

SpringBoot-IDEA 快速入门

3 选择web

SpringBoot-IDEA 快速入门

4 项目名称

SpringBoot-IDEA 快速入门

5 生存项目 修改  pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

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

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

6 创建 HelloWorld   编写controller内容 注意: @Controller

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class HelloWorld {

    @RequestMapping("/hello")
    @ResponseBody
    public  String ShowHelloWorld()
    {

        return  "HelloWorld";

    }


}

或者

 

package com.example3.demo2.Log;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

   // @RequestMapping("/user")
   // @RequestMapping(value = "/user",method = RequestMethod.GET)

    @RequestMapping("user")
    public String user() {

      //  log.error("Hi ! We have an Error. Hello World");

        return "Hello World ----spring-boot-log4j2";
    }
}

7 创建APP类 运行 SpringBoot

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication --起动SpringBoot
public class App {

     public static  void main(String[] args)
     {

         SpringApplication.run(App.class,args);
     }
}

8 访问 /hello

SpringBoot-IDEA 快速入门