项目搭建
创建项目

配置项目信息

依赖选择
- 可选可不选,根据实际需求来,主要都是后期导入;先选择的话,选择Web下的SpringWeb以及Template Englines下的Thymeleaf就够用了;SQL可以勾选MySQL Driver,JDBC API 和MyBatis Framework;这里只选择SpringWeb以及Thymeleaf。

修改存放路径

项目结构

简单配置
- 在resources目录下新建application.yml,并写入如下信息(可不配置)
server:
port: 8070 #端口号
servlet:
context-path: /test #项目访问路径 即浏览器输入的路径 :localhost:8070/test
- 启动项目不报错即搭建成功

运行测试
- 在
src/main/java/com/jiumozhai
目录下新建Controller包

- 新建TestController类,写入测试代码
package com.jiumozhai.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TestController {
@RequestMapping(value = {"/index",""})
@ResponseBody
public String test(){
return "Hello World";
}
}
- 运行项目并在浏览器对应路径查看运行结果
一个简单的SpringBoot项目就运行成功了,更多的内容可以参看中文文档。
评论区