IDEA搭建SpringBoot项目

目录

一、IDEA创建SpringBoot项目

1、创建新项目
在这里插入图片描述
2、创建springboot项目
在这里插入图片描述
当出现json解析问题而无法创建springboot项目,如图
在这里插入图片描述
此种情况下的解决方法:改用Custom方式,输入网址https://start.aliyun.com/。如下图:
在这里插入图片描述
3、设置项目属性
在这里插入图片描述
4、初始化时添加基本的依赖包(web依赖)
在这里插入图片描述
5、设置工程路径
在这里插入图片描述
6、springboot项目创建完成,下图中红框部分文件可以删除
在这里插入图片描述

二、配置全局配置

在application.yml或appplication.properties文件中输入如下配置:
在这里插入图片描述

三、thymeleaf模板访问html页面

1、springboot项目在使用thymeleaf模板时默认web入口是在templates文件夹下,在templates文件夹下随便写一个html文件,此处以index.html文件为例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
    <h1>首页</h1>
</body>
</html>

2、在pom.xml文件中添加thymeleaf依赖

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

3、创建controller访问控制器,此处在com.example.test_example路径下创建IndexController.java控制器,如下:

/**
 * TODO
 *
 * @author Cll
 * @date 2020/6/1
 */
@Controller
public class IndexController {

    @GetMapping("/index")
    public String index() {
        return "index";
    }
}

4、运行项目后,在浏览器中输入127.0.0.1:8080/te/index或者localhost:8080/te/index,成功显示的效果图如下所示:
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值