spring boot快速上手

springBoot快速上手

创建spring boot项目

1.idea开发工具
file-new project-
spring boot快速上手_第1张图片
选择需要的相关组件
spring boot快速上手_第2张图片
2.访问https://start.spring.io/创建,下载zip包解压导入
spring boot快速上手_第3张图片

项目的结构

spring boot快速上手_第4张图片

pom.xml配置文件



    4.0.0
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.4.RELEASE
         
    
    
    com.example
    demo
    0.0.1-SNAPSHOT
    war
    demo
    Demo project for Spring Boot

    
        1.8
    

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

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

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


spring boot项目的启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*每个项目只有一个这样的注解*/
@SpringBootApplication
public class DemoApplication {

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

}

新建一个测试类

@RestController
/*@RestController是一个组合注解,放回json字符串*/
public class OneTest {
/*路径为start,请求方式get*/
    @RequestMapping(value = "/start",method =RequestMethod.GET)
    public String start(){
        return "helllwork";
    }
    @RequestMapping(value = "/begin",method =RequestMethod.GET)
    public String begin(){
        return "index";
    }
}

访问

spring boot快速上手_第5张图片

你可能感兴趣的:(spring boot快速上手)