SpringBoot直接访问templates下的html问题

方法1:曾经:
template下文件不允许直接访问
1、springboot项目默认是不允许直接访问template下的文件的,是受保护的。
所以想访问template下的html页面,我们可以配置视图解析器。

2、如果想要用视图去展示,应该要设置好视图展示页面,比如说用一个模板语言来接收返回的数据(thymeleaf或者freemarker等), 也可以用jsp接收,但是SpringBoot官方是不推荐用jsp的,而是建议使用thymeleaf作为模板语言,这里我以thymeleaf为例。

方法2:现在(推荐的方法)

知道需要通过控制器跳转才能访问到templates下的html文件
因为springboot默认访问static,resources,public这些文件夹下的文件,而没有默认访问templates下的
我们需要在配置加上

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/

完整例子:

spring:datasource:name: druidtype: com.alibaba.druid.pool.DruidDataSourcedruid:driver-class-name: com.mysql.jdbc.Driverfilters: statpassword: 123456url: jdbc:mysql://127.0.0.1:3306/ugaoxin_db?useUnicode=true&characterEncoding=UTF-8username: rootthymeleaf:prefix:  /templates/**suffix: .htmlcache: falseresources:static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/server:port: 8082

SpringBoot怎么直接访问templates下的html页面相关推荐

  1. thyme leaf不能直接访问templates下的html页面

    搞忘了,要通过controller来跳转到html页面,不能直接访问templates下的html页面 比如要到达index2.html 则在controller中

  2. springboot项目无法访问webapp下的html页面

    之前一直做的是前后分离的项目,所以不需要考虑html的访问问题,最近在加流程方面的东西,发现将html放到webapp无法访问,处理费方法如下: 第一种方式:将静态文件放到resources目录下,s ...

  3. SpringBoot打成jar包时访问templates下的html出错或访问不到

    SpringBoot打成jar包时访问templates下的html出错或访问不到 问题描述 背景 在Springboot项目中,本地环境下(idea)中,访问html文件的方式如图结构 问题 打成j ...

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

    运随心转,相由心生 需要一个百里香来实现,不不,是thymeleaf来实现. 1.添加依赖包 在pom.xml文件里面 org.springframework.boot spring-boot-sta ...

  5. [乐意黎原创]访问Centos下Apache主机页面抛You don't have permission to access / on this server.

    Forbidden You don't have permission to access / on this server. Server unable to read htaccess file, ...

  6. Springboot直接访问templates中的html

    Springboot默认不能访问templates中的页面,只能通过Controller进行页面跳转,如果需要直接访问templates中的html需要进行配置,相关配置如下. 传统的MVC模式可以在 ...

  7. SpringBoot项目中访问HTML页面

    SpringBoot默认的页面映射路径(即模板文件存放的位置)为"classpath:/templates/*.html".静态文件路径为"classpath:/stat ...

  8. eclipse spring mysql,eclipse环境下的springboot框架+mybatis访问MySQL报错空指针

    "/")public classTestController { @RequestMapping("/login")publicString login() { ...

  9. Java springboot访问templates的html和静态资源

    1.设置配置文件application.properties server.port=8088spring.mvc.view.prefix=templates/ spring.mvc.view.suf ...

最新文章

  1. The project cannot be built until build path errors are resolved的解决方法
  2. Exchange 数据库邮箱的修复
  3. 详解网络摄像机中的IR-CUT
  4. jenkins搭建_自动化测试系列之jenkins配置搭建环境
  5. 学习java的经典书籍
  6. ssm框架使用重定向报404_如何在 ASP.NET Core MVC 中处理 404 错误
  7. 手动建立makefile简单实例解析
  8. 特斯拉回应海南碰撞事故:地面湿滑 车主踩制动踏板幅度较轻
  9. Python pipenv
  10. c# export server 调用sql_C#调用SQL Server参数过程传参
  11. Ooooops! 这通骚扰电话是AI机器人打的(浙大出品,中文很6)
  12. python筛选时间段_django admin管理工具自定义时间区间筛选器DateRangeFilter介绍
  13. 过山车大亨3白金版 mac版(模拟经营类游戏)支持m1
  14. MDK5软件入门之新建工程项目模板
  15. 问题记录——Unity PackageManager下载失败
  16. 数据科学 IPython 笔记本 8.16 地理数据和 Basemap
  17. 数据分析师面试常见的77个问题
  18. 为什么程序员做外包会被瞧不起?
  19. linux nagios 监控,Nagios 监控 Linux 主机
  20. linux 安装环境

热门文章

  1. c# 2维数组 取一维_C#| 不同类型的一维数组声明
  2. python爬虫反爬 css 知乎 专栏_反反爬虫系列(四)
  3. 人生苦短python作伴_“人生苦短,我用Python”
  4. java的parse方法_Java即时类| parse()方法与示例
  5. 回文子序列_计算回文子序列的总数
  6. 线性代数向量乘法_标量乘法属性1 | 使用Python的线性代数
  7. 爱了!蚂蚁开源的“SpringBoot”框架,新增了这6项功能...
  8. 【C++】For循环同时初始化两个变量
  9. Android 运行时异常 Binary XML file line # : Error inflating class
  10. 计算机网络(第四章网络层)