Spring Boot项目搭建和测试

  1. 项目创建

    IDEA选择新建项目,选择Spring Initialize,点击next
    1

    设置好包名和Java版本后选择需要添加的依赖后完成创建

2
在这里插入图片描述

  1. 配置数据库和thymeleaf

    application.yml中配置数据库的连接和thymeleaf

    spring:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
        username: user0
        password: 123456
    
      thymeleaf:
        mode: HTML
      profiles:
        active: dev
    
  2. 构建基本结构

    结构与ssm基本相同,static用来存储静态资源,templates存储界面等模板
    3

  3. 编写代码测试

    templates\first.html中编写一个html文件

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    欢迎!
    </body>
    </html>
    

    com.llanero.springboot_test.web.IndexController中控制显示该页面

    package com.llanero.springboot_test.web;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.GetMapping;
    
    @Controller
    public class IndexController {
    
        @GetMapping("/")
        public String index() {
            return "first";
        }
    }
    
  4. 测试结果
    4

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值