SpringBoot之使用Thymeleaf以及WebJars

第一步:在IDEA中使用Spring Initializr快速创建SpringBoot,添加Web模块

工程目录:
SpringBoot之使用Thymeleaf以及WebJars_第1张图片

第二步:引入相关依赖

pom.xml



	4.0.0

	cn.yujiago
	spring-boot-web-restfulcrud
	0.0.1-SNAPSHOT
	jar

	spring-boot-web-restfulcrud
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.3.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
		3.0.9.RELEASE
		
		
		2.2.2
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		
        
		
			org.springframework.boot
			spring-boot-starter-thymeleaf
		
		
		
			org.webjars
			jquery
			3.3.1
		
        
		
			org.webjars
			bootstrap
			4.0.0
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	
	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	

第三步:使用Thymeleaf以及引入js

html




    
    Signin Template for Bootstrap
	
	
	
	




PS:这里th标签会覆盖相应的属性值

注意:只需要将需要Thymeleaf渲染的文件放到/templates下即可交由Thymeleaf引擎渲染

原理:

@ConfigurationProperties(
    prefix = "spring.thymeleaf"
)
public class ThymeleafProperties {
    private static final Charset DEFAULT_ENCODING;
    public static final String DEFAULT_PREFIX = "classpath:/templates/";
    public static final String DEFAULT_SUFFIX = ".html";
    private boolean checkTemplate = true;
    private boolean checkTemplateLocation = true;
    private String prefix = "classpath:/templates/";
    private String suffix = ".html";
    private String mode = "HTML";

相关配置

#thymeleaf
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.suffix=.html
#默认严格检查
#spring.thymeleaf.mode=HTML5
#非严格检查
spring.thymeleaf.mode=LEGACYHTML5

《Thymeleaf使用文档》

你可能感兴趣的:(#,SpringBoot,【SpringBoot】)