SpringBoot学习-支持thymeleaf模板引擎
来源:互联网 发布:rends a10 2代编程 编辑:程序博客网 时间:2024/05/17 15:38
Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎。配置过程比较简单,引入jar支持就行
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>application.properties文件配置一些信息(非必须)
#thymelea模板配置spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.cache=falsespring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html基本上就可以了,现在写个controller测试一下
@Controllerpublic class Test2Controller { @RequestMapping("to") public String to(){ return "hello"; } @RequestMapping("test") public String test(){ return "test"; }}注意一点,controller的注解是@Controller,而不是@RestController,区别在项目搭建的时候说过
在templates目录下新建几个页面,SpringBoot有个默认首页的设置,可以把index.html放在static静态资源目录下,就可以直接访问了
注意:HTML中引用Js和CSS的文件需要也放在static目录下才能被正确访问
测试结果:
有一个小问题:
IDEA创建的HTML文件默认的meta标签内是没有收尾的,会引起报错,我们加上收尾的“/”就行.
阅读全文
0 0
- SpringBoot学习-支持thymeleaf模板引擎
- SpringBoot Thymeleaf 模板引擎
- springboot webmvc thymeleaf 模板引擎
- SpringBoot使用thymeleaf模板引擎
- SpringBoot整合模板引擎Thymeleaf
- java springboot Thymeleaf模板引擎
- springboot之模板引擎 --- thymeleaf
- springboot之thymeleaf模板引擎章节
- Thymeleaf模板引擎 学习笔记
- 一起学习thymeleaf模板引擎
- SpringBoot学习(三)从yml文件中获取数据和Thymeleaf 模板引擎
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- SpringBoot-07引擎模板thymeleaf和freemarker的使用
- SpringBoot-thymeleaf模板集成
- springboot整合thymeleaf模板
- SpringBoot整合thymeleaf模板
- SpringBoot集成Thymeleaf模板
- Thymeleaf 模板引擎
- Android Studio
- 配置 Fiddler 抓取 HTTPS 请求
- npm镜像安装和使用方法
- Docker入门
- Python 猜数字游戏,解决变量类型异常问题
- SpringBoot学习-支持thymeleaf模板引擎
- 编程语言分类,编译型、解释型、和静态与动态
- Pentaho Kettle Solutions (读书笔记)【2. Kettle基本概念】
- Maven远程部署war包到Tomcat
- PHP配置可修改范围
- Linux基础入门(三)-- 学习笔记
- android 安装应用
- Oulipo
- eclipse新建service(tomcat服务器)时出错