SpringBoot+Thymleaf

一、如何不重启程序修改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=<encoding> 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.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <version>1.3.0.RELEASE</version>
</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   

如下:

<!DOCTYPE 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 UP</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <!--[if lte IE 8]>
    <script src="../static/assets/js/ie/html5shiv.js" th:src="@{assets/js/ie/html5shiv.js}"></script><![endif]-->
    <link rel="stylesheet" href="../static/assets/css/main.css" th:href="@{assets/css/main.css}"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="../static/assets/css/ie8.css" th:href="@{assets/css/ie8.css}"/><![endif]-->
</head>

其中:

<link rel="stylesheet" href="../static/assets/css/main.css" th:href="@{assets/css/main.css}"/>

访问:
http://localhost:8080/assets/js/jquery.min.js

三、Application应该放置在根包路径下:
这里写图片描述
四、其他

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";
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值