SpringBoot快速入门

1.1 创建Maven工程

 

1.2 添加SpringBoot的起步依赖

<?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>

    <groupId>com.taojunrui</groupId>
    <artifactId>springboot_demo</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>
    <dependencies>
        <!--SpringBoot要集成SpringMVC进行Controller的开发,所以项目要导入web的启动依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

1.3编写SpringBoot引导类

package com.taojunrui;

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

//要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问
@SpringBootApplication
public class MySpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class);
    }

}

1.4 编写Controller

package com.taojunrui.com.taojunrui.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//在引导类MySpringBootApplication同级包或者子级包中创建QuickStartController
@Controller
public class QuickStartController {
    @RequestMapping("/quick")
    @ResponseBody
    public String quick(){
        return "springboot 访问成功!";
    }
}

1.5 测试

 

通过日志发现,Tomcat started on port(s): 8080 (http) with context path ''

tomcat已经起步,端口监听8080

打开浏览器访问url地址为:http://localhost:8080/quick

 

posted @ 2022-04-20 15:33  桃小陶  阅读(40)  评论(0)    收藏  举报