天天看点

【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目

搭建一个SpringBoot项目

  1. 新建文件

    打开IDEA -> New -> New Project -> Spring Initializr 使用默认 点击next

    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    选择依赖,根据你的项目需要进行勾选,我根据自己项目需要选择了如下
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    选择好之后点击next-> finish
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
  2. 配置Maven
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
  3. 配置数据库(本次只是新建一个sspringboot项目,暂时用不到数据库,但是还是需要在配置文件中配置好)

    首先新建一个数据库,名字为spring,目前没建立新表。

    修改配置文件,根据自己学习来,我是将properties文件改成yml文件(直接重命名改后缀),再用yml进行配置数据库相关信息

    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    在pom.xml文件下修改数据库连接版本和自己当前数据库版本一致
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
  4. 文件创建目录如图:
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目

    first.html用来查看效果,新建一个控制器用来跳转到first界面

    first.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>标题</title>
</head>
<body>
myFirstSpringBoot
</body>
</html>
           

index.controller

@Controller
public class indexController {

    //跳转页面
//    @GetMapping("/") //等价于下面一行
    @RequestMapping(method = RequestMethod.GET,value = "/")
    public String index(){
        return "first";
    }
}
           
  1. 运行效果
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    打开8080端口查看
    【学习日记】(SpringBoot-part 1)初学springboot—创建springboot项目
    运行成功