一、如何不重启程序修改html:
1、只需要在application.properties进行配置即可:
########################################################
###THYMELEAF (ThymeleafAutoConfiguration)
########################################################
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
#spring.thymeleaf.encoding=UTF-8
# ;charset= is added
#spring.thymeleaf.content-type=text/html
# set to false for hot refresh
spring.thymeleaf.cache=false
2、spring.thymeleaf.cache 设为false或者使用springboot的devtools
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<version>1.3.0.RELEASEversion>
dependency>
3、如果使用的开发工具是 idea ,修改 html 后使用 Ctrl + Shift + F9
二、资源文件的约定目录结构
Maven的资源文件目录:/src/java/resources
spring-boot项目静态文件目录:/src/java/resources/static
spring-boot项目模板文件目录:/src/java/resources/templates
spring-boot静态首页的支持,即index.html放在以下目录结构会直接映射到应用的根目录下:
classpath:/META-INF/resources/index.html
classpath:/resources/index.html
classpath:/static/index.html
calsspath:/public/index.html
如下:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<title>Alpha By HTML5 UPtitle>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="../static/assets/css/main.css" th:href="@{assets/css/main.css}"/>
head>
其中:
<link rel="stylesheet" href="../static/assets/css/main.css" th:href="@{assets/css/main.css}"/>
访问:
http://localhost:8080/assets/js/jquery.min.js
springboot+thymeleaf报错:java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘user’ available as request attribute
报错的原因是因为html页面中的${user}并没有定义,不想jsp页面中直接对象的属性对应就可以了,这里是当你从控制器进入这个页面的时候就需要把这个对象模型传到前台。
@GetMapping(value = "/reg")
public String userRegister(Model model){
User user = new User();
model.addAttribute("user",user);
return "/userAdd";
}