2. SpringBoot起步练习

1.新建一个SpringBoot模块

新建模块

1.1项目名可以根据自己需要,我这里是默认
01

1.2注意这里什么都不需要勾选(自己添加依赖包)

02

1.3完成新模块的创建

03

1.4建好之后如图

04

2.SpringBoot起步练习

  • pom.xml添加依赖


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.3.RELEASE
         
    
    com.springboot
    quickstart
    0.0.1-SNAPSHOT
    quickstart
    Demo project for Spring Boot

    
        UTF-8
        1.8
    

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

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

  • HelloController类
package com.springboot.quickstart.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *SpringBoot的第一个RESTful请求
 */
@RestController
public class HelloController {

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String getHello(){
        return "Hello,Spring Boot";
    }
}
  • Application启动主类
package com.springboot.quickstart;

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

/**
 * SpringBoot的启动主类
 */
@SpringBootApplication
public class QuickstartApplication {

    public static void main(String[] args) {
        SpringApplication.run(QuickstartApplication.class, args);
    }

}
  • 运行结果(出现这两行运行成功)


    05
  • postman运行结果


    06

你可能感兴趣的:(2. SpringBoot起步练习)