SpringBoot-IDEA 快速入门

一  快速入门

1maven构建项目

SpringBoot-IDEA 快速入门_第1张图片

2 点 Next

SpringBoot-IDEA 快速入门_第2张图片

3 选择web

SpringBoot-IDEA 快速入门_第3张图片

4 项目名称

SpringBoot-IDEA 快速入门_第4张图片

5 生存项目 修改  pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.3.RELEASE
         
    


    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



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 快速入门_第5张图片

你可能感兴趣的:(SpringBoot)