欢迎来到Wzzzq的博客

 

spring boot快速上手

springBoot快速上手

创建spring boot项目

1.idea开发工具
file-new project-

选择需要的相关组件

2.访问https://start.spring.io/创建,下载zip包解压导入

项目的结构

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>
    <!--spring boot的parent-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <!--项目的属性,版本号,打包方式等等-->
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
<!--Java的版本-->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--作为web项目必须引入的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--spring单元测试的模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
 </dependencies>
<!--构建maven的一个插件-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

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";
    }
}

访问

posted @ 2020-06-26 00:59  Wzzzq  阅读(144)  评论(0编辑  收藏  举报