spingboot html 图片,springboot配置html页面

最近写了一下springboot , 碰到了一个配置 html 的问题 , 专门 记录一下

首先 说明 , 有两种 访问html 的方式

1.通过后台跳转到 html 页面

现在比较流行的开发模式就是 前后端分离,  在分离的情况下 , 就无法直接访问到 html  , 需要通过 后端来跳转

(1.) 添加maven

org.springframework.boot

spring-boot-starter-thymeleaf

(2.) 配置 application.yml

spring:

thymeleaf:

prefix:

classpath: /templates # 访问template下的html文件需要配置模板,映射

cache: false # 开发时关闭缓存,不然没法看到实时页面

(3) controller

@Controller

@RequestMapping("/delete/")public classdeleteController {

@RequestMapping("wrong")publicString index() {return "wrong";

}

}

注意 :

访问方法跳转页面 方法请求加/ 返回到某一个页面不用.后缀名 并且类上的注解改为@controller 不是@rest Controller

通过访问 localhost:8080/delete/wrong   就可以访问到 templates下的wrong.html页面.

2.直接访问 html 页面

配置applicaiton.yml

不用通过方法访问页面

spring:

resources:static-locations: classpath:/static/, classpath:/templates/

就可以通过 localhost:8080/wrong.html 访问

感谢  知知.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值