静态资源路径
静态资源支持放在以下路径中,访问优先级从上到下:
classpath:/meta-inf/resources/
classpath:/resources/
classpath:/static/ # 默认路径
classpath:/public/
其中 classpath 为 src/main/resources 目录。
请求地址为:http://localhost:8080/xx.js
首页
文件位置:
classpath:/static/favicon.ico
classpath:/templates/
导入 thymeleaf 模板引擎依赖:
<dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> </dependency> <dependency> <groupid>org.thymeleaf</groupid> <artifactid>thymeleaf-spring5</artifactid> </dependency> <dependency> <groupid>org.thymeleaf.extras</groupid> <artifactid>thymeleaf-extras-java8time</artifactid> </dependency> </dependencies>
定义请求控制器:
@controller public class indexcontroller { @requestmapping({"/", "/"}) public string index(model model){ model.addattribute("msg", "hello, thymeleaf!"); return "index"; } }
加入模板内容显示首页:
<!doctype html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="utf-8"> <title>index page</title> </head> <body> <h1>首页</h1> <div th:text="${msg}"></div> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论