Ps:如果页面出不来效果,F12出现“jquery.js:1 Failed to load resource: the server responded with a status of 404 ()“等报错,那就是没有引入外部js,css的错啦。
话不多说直接上解决方案:
1.检查是否加了依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.application.properties是否加了配置:
#thymelea模板配置
spring.thymeleaf.prefix=classpath:/templates/
# templates中的所有文件后缀名
spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
#spring.resources.chain.strategy.content.enabled=true
#spring.resources.chain.strategy.content.paths=/**
3.检查.html文件是否放在了resource–>templates文件夹路径下,以及css,js等的外部包是否放在了resource–>static文件夹路径下。
4.。html文件里引入方式为:
<script th:src="@{/js/jquery.js}" type="text/javascript"></script>
从static位置后开始写,如果想静态编辑一起引入,可以:
<script th:src="@{/js/jquery.js}" src="../static/js/jquery.js" type="text/javascript"></script>
over.打完收工。