Springboot入门 5分钟快速搭建Springboot框架

3分钟快速搭建Springboot框架

如何搭建springboot框架 废话不多说直接开搞

首先打开idea新建 选择Spring Initializr,点击next
在这里插入图片描述
在这里插入图片描述
选择web springweb 有的是两个web 这个也是一样的
在这里插入图片描述
之后项目会自己下载一些依赖
在这里插入图片描述
项目页面

ok 我们现在启动项目 这是项目成功启动后的样子 这时我们打开浏览器 输入http://localhost:8080
在这里插入图片描述在输入localhost:8080之后 显示页面404 代表已经成功了 因为我们项目还没有放入页面 所以显示404
在这里插入图片描述
好我们现在写了一个小接口 之后打开浏览器输入http://localhost:8080/test就成功返回了我们返回的数据
在这里插入图片描述放代码

package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {
    
    
    
@ResponseBody
@RequestMapping("/test")
    public String test(){
    
    
        return "成功";
    }
}

http://localhost:8080/test
在这里插入图片描述接着 springboot项目如何访问页面
这里我用的springboot专用模板 thymeleaf 后面也会出这个模板的教程

先在配置文件配置一下访问路径
在这里插入图片描述

#配置文件信息
spring.thymeleaf.prefix=classpath:/static/
spring.thymeleaf.suffix=.html

接着引入thymeleaf的模板依赖

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

接着写接口
这次要去掉@ResponseBody注解 这个注解的作用是接口返回数据时使用
在这里插入图片描述
再次浏览器输入http://localhost:8080/test 成功访问页面
在这里插入图片描述
好了到这里springboot框架已经搭建完成了 有不会的问题可以评论

猜你喜欢

转载自blog.csdn.net/qq_44664329/article/details/108979539