最近在学习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

最新文章

  1. Java中,异常的处理及抛出
  2. 微信——获取用户基本信息及openid 、access_token、code
  3. CRC16 三种算法及c实现
  4. hdoj 5003
  5. 用python做爬虫的例子
  6. 添加iPhone设备的udid之后,重新生成开发证书(Development)
  7. Sql 高效分页
  8. CSS 定位元素之 relative
  9. TXMLDocument换行的两种方案
  10. POJ 3111 K Best(二分答案)
  11. POJ 1028 Web Navigation 题解
  12. 201521123052《Java程序设计》第8周学习总结
  13. 中介者模式(Mediator)
  14. 快速增加controller节点
  15. TPYBoard读取芯片上的温度传感器
  16. Beta敏捷冲刺每日报告——Day4
  17. Markdown语法及SublimeText下使用技巧
  18. Python编写守护进程程序
  19. mybatis的延迟加载、一级缓存、二级缓存
  20. java.lang包【Object类】

热门文章

  1. st表(poj3264)
  2. 【.NET Core项目实战-统一认证平台】第六章 网关篇-自定义客户端授权
  3. Linux 比较判断运算(if else)
  4. Microsoft Azure IoTHub Serials 2 - 如何为android应用添加IoTHub支持
  5. Akka-CQRS(4)- CQRS Writer Actor 示范
  6. Mac 系统安装教程
  7. Java工程师必备
  8. 《深入浅出nodejs》读书笔记(2)
  9. python中 __init__.py的例程
  10. 利用node 剥取其他网站的文档数据结构 ---