springboot如何访问html页面,springboot项目如何访问项目中的html页面

运随心转,相由心生

需要一个百里香来实现,不不,是thymeleaf来实现。

1、添加依赖包 在pom.xml文件里面

org.springframework.boot

spring-boot-starter-thymeleaf

2、配置这个模板

在application.properties里面配置

spring.thymeleaf.prefix=classpath:/templates/

3、在templates文件夹里面新建一个html5文件

springboot+mybatis的增删改查

springboot+mybatis的增删改查

4、新建一个java文件

package com.control;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

@RequestMapping("/index")

public class JspControl {

@RequestMapping("/index")

public String index(){

return "index";

}

}

尝试一、运行程序,打开浏览器,输入http://localhost:8080/项目名称/jsp/index/

输入回车

e3af83c28bd8eaea4d2f1fcc6cc5a8ba.png

突然报错

007d0bdd8a4d7db064a0afb5cf7e102b.png

原来是我的入口程序放错了位置......

7a49cb35b850448b1027094f876ff239.png

记住,不需要项目名称的,直接http://localhost:8080/jsp/index/

cae956e7a281b3930eaca53a9df3de33.png

总结: 需要thymeleaf依赖实现,在pom.xml文件中导入依赖,然后在application.properties文件里面配置thymeleaf依赖的基础信息;在java中设置一下访问html的路径;

运随心转,相由心生

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值