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 @   桃小陶  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示