最近在学习springbooot2 和 thymeleaf

程序文件

application.properties文件配置:

#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML
spring.thymeleaf.check-template-location=true
# 静态文件请求匹配方式
spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录
spring.resources.static-locations = classpath:/templates/,classpath:/resources/,classpath:/static/,classpath:/public/
#热部署生效
spring.devtools.restart.enabled=true

 在编译的时候,发现一直报这个错误:

 

 Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)

  之后再网上找了各种答案,发现都不能使用

-------------------------------------------------------------------------------------------------------------------

下面是正确的方案:

在pom.xml中引入如下配置

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<!--加载资源目录-->
<directory>src/main/resources</directory>
<includes>
<!--加载配置文件-->
<include>**/*.xml</include>
<include>**/*.properties</include>
<!--加载模板文件-->
<include>**/*.html</include>
<!--加载静态文件-->
<include>/static/</include>
</includes> </resource>
</resources>
</build>

  在pom.xml中引入的文件,这样application.properties文件中可注释文件路径配置。

server.port=9099
#thymeleaf
#spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML
spring.thymeleaf.check-template-location=true
# 静态文件请求匹配方式
#spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录
#spring.resources.static-locations = classpath:/templates/,classpath:/resources/,classpath:/static/,classpath:/public/
#热部署生效
spring.devtools.restart.enabled=true

  

LoginController中:

package com.java.seckill.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/index")
public String Index() {
return "login";
} @RequestMapping("/login")
@ResponseBody
public Boolean login(){
return true;
}
}

  

直接访问:http://localhost:9099/login/index

springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)的更多相关文章

  1. spring加载资源文件中classpath*与classpath的区别

    在spring和MyBatis继承的时候,配置mapperLocations.一开始配置是这样的. 需要加载路径为com/thomas/base/mapper和com/thomas/bu/mapper ...

  2. Spring boot 国际化自动加载资源文件问题

    Spring boot 国际化自动加载资源文件问题 最近在做基于Spring boot配置的项目.中间遇到一个国际化资源加载的问题,正常来说只要在application.properties文件中定义 ...

  3. Style样式的四种使用(包括用C#代码动态加载资源文件并设置样式)

    Posted on 2012-03-23 11:21 祥叔 阅读(2886) 评论(6) 编辑 收藏 在Web开发中,我们通过CSS来控制页面元素的样式,一般常用三种方式: 1.       内联样式 ...

  4. Maven,预加载资源文件

    预加载资源文件需要先启用功能: <build> <resources> <resource> <directory>src/main/resources ...

  5. 动态加载资源文件(ResourceDictionary)

    原文:动态加载资源文件(ResourceDictionary) 在xaml中控件通过绑定静态资源StaticResource来获取样式Style有多种方式: 1.在项目的启动文件App中<App ...

  6. Java加载资源文件的两种方法

    处理配置文件对于Java程序员来说再常见不过了,不管是Servlet,Spring,抑或是Structs,都需要与配置文件打交道.Java将配置文件当作一种资源(resource)来处理,并且提供了两 ...

  7. PyQt5(5)——加载资源文件

    在实际中我们需要美化界面,就需要许多的自定义图片. 但是我们发现直接导入图像使用,等程序运行时会报错.???? 这就需要建立资源文件并且加载它们,程序就可以顺利运行了. 设计界面是如何加载资源文件呢? ...

  8. NHibernate动态加载资源文件

    最近做项目,又用到了以前做过的ORM框架--NHibernate. 此次想要实现的目标: 1.简单SQL用NHibernate的Session的CRUD方法实现 2.复杂SQL用Native SQL实 ...

  9. Java加载资源文件几种方法

    from: http://andyzhu.blog.51cto.com/4386758/775836/ import java.net.URL; import org.springframework. ...

随机推荐

  1. 6 week work 2

    CSS颜色表示法和颜色表(调色板) 1.用颜色名表示 如:white.red.greenyellow.gold等. 2.用十六进制的颜色值表示(红.绿.蓝) #FF0000或者#F00 3.用rgb( ...

  2. CENTOS7常用的基础命令集合(一)

    目录(?)[-] CentOS7 常用命令集合 常用命令 文件与目录操作 查看文件内容 文本内容处理 查询操作 压缩解压 yum安装器 网络相关 系统相关 系统服务启动相关 防火墙相关 RPM包管理 ...

  3. 一把梭系列 之 颜值不够VsCode来凑

    如果您的孩子不适应编译型语言怎么办? 如果您的孩子贪玩不想花多时间在编程上怎么办? 如果您还没有孩子怎么办? 如果您夜晚兼职觉不够睡又怎么办? 不妨试试 “ 拍 簧 片 ”. 妈了巴子的有点麻烦,但别 ...

  4. MyBatis 的动态 SQL 使用说明

    动态SQL简介 参考文档地址:http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 ...

  5. txt文本处理---行未添加逗号

    做音频处理过程中,经常遇到需要对文本进行转换,今天就遇到了一个行末加逗号的问题,找到了几种有效的方式,做个记录吧. 以下是几种方法实现: python代码实现: import os with open ...

  6. [部署]CentOS安装PHP环境

    环境 虚拟机:VMWare10.0.1 build-1379776 操作系统:CentOS7 64位 HTTP Server:Apache(httpd) 步骤 PHP环境需要HTTP服务器支持,本文使 ...

  7. express脚手架的安装,以及ejs的语法

    express 1.建一个项目  npm init -y 初始化一下项目 2.cnpm install express -S 安装express模块 3.cnpm init 安装依赖 !ejs模板是后 ...

  8. sql server 性能调优之 资源等待之网络I/O

    一.概述 与网络I/O相关的等待的主要是ASYNC_NETWORK_IO,是指当sql server返回数据结果集给客户端的时候,会先将结果集填充到输出缓存里(ouput cache),同时网络层会开 ...

  9. 纸上谈兵: AVL树[转]

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 二叉搜索树的深度与搜索效率 我们在树, 二叉树, 二叉搜索树中提到,一个有n个节点 ...

  10. Google的java工具类Guava

    前言 google开发java项目肯定也不想重复造轮子,所以肯定也有工具类,就是它了:Guava 我将举例几个实际的例子,发挥这个工具类好用的功能.更多的方法和功能,还有内部的实现可以直接参考http ...