SpringBoot前端模板
Springboot支持thymeleaf、freemarker、JSP,但是官方不建议使用JSP,因为有些功能会受限制,这里介绍thymeleaf和freemarker。
一、thymeleaf模板
thymeleaf模板的前端界面为.html格式的文件,可以直接使用浏览器进行查看,方便进行样式等方面的调试。
1、pom依赖添加
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2、application属性配置
查看官方文档的默认配置介绍如下:
这里必须要注意的是,开发的时候要关闭模板缓存,不然修改界面文件后无法实时显示。在application.properties文件中关闭模板缓存:
spring.thymeleaf.cache=false
关闭缓存后,修改html文件,可以直接Ctrl+F9编译后,显示最新的修改内容。
3、编写界面
我的界面hello.html路径为:templates/template/hello.html,代码:
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head><title>Title</title> </head> <body><!--/*@thymesVar id="name" type="java.lang.String"*/--><p th:text="'Hello, ' + ${name}" ></p> </body> </html>
4、编写controller
package com.example.demo.template;import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping;@Controller @RequestMapping("/html") public class HtmlController {@RequestMapping("/hello")public String hello(Model model) {model.addAttribute("name", "world");return "template/hello";} }
运行访问,如下:
thymeleaf具体使用参考
http://blog.csdn.net/z719725611/article/details/53908294
二、freemarker模板
1、pom依赖添加
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency>
注意:允许thymeleaf和freemarker同时存在
2、application属性配置
查看官方文档的默认配置介绍如下:
application.properties文件无需配置,使用默认配置即可
3、编写界面
我的界面hello.ftl路径为:templates/ftl/hello.ftl,代码:
<!DOCTYPE html> <html> <head><title>Title</title> </head> <body>message:${message} </body> </html>
4、编写controller
package com.example.demo.template;import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping;@Controller @RequestMapping("/html") public class HtmlController {@RequestMapping("/hello")public String hello(Model model) {model.addAttribute("name", "world");return "template/hello";} }
接下来启动运行即可。
freemarker具体使用参考
http://blog.csdn.net/fhx007/article/details/7902040/
http://blog.csdn.net/tang9140/article/details/39695653
转载于:https://www.cnblogs.com/diaozhaojian/p/10578237.html
SpringBoot前端模板相关推荐
- 个人博客前端模板_博客设计——概述
在目前已有的许多社交软件及平台中,博客始终保持着自己的地位,始终有一大批学生和各行各业职业人员喜欢通过博客的方式记录和分享自己在生活中或者学术上等各方面的经验,这不仅方便发表者个人今后解决类似的问题, ...
- Springboot 读取模板excel信息内容并发送邮件, 并不是你想想中的那么简单
Springboot 读取模板excel信息内容并发送邮件 背景 技术选型 搭建过程 数据加密 隐藏问题暴露 背景 追溯 解决 背景 在我们日常开发中, 会遇到这样一种场景, 就是读取表格中的数据, ...
- 前端模板引擎 artTemplate的 使用与进阶
前端模板引擎 artTemplate的 使用与进阶 查看全文 http://www.taodudu.cc/news/show-3760040.html 相关文章: springboot 整合 free ...
- swig模板 PHP,nodejs前端模板引擎swig入门
相对于jade,我还是更喜欢swig前端模板引擎,jade虽然语法简练高效了不少,但是在我这最大的问题是 他没有一个html该有的样子... 所以我还是决定使用swig,页面结构,样子都是熟悉的样子, ...
- (转)【前端模板之路】一、重构的兄弟说:我才不想看你的代码!把HTML给我交出来!...
原文地址:http://www.cnblogs.com/chyingp/archive/2013/06/30/front-end-tmplate-start.html 写在前面 随着前端领域的发展和社 ...
- inspinia前端模板怎样修改图标
场景 inspinia前端模板官网: http://cn.inspinia.cn/layouts.html 离线版2.8下载: https://download.csdn.net/download/b ...
- inspinia前端模板怎样编写消息提示框点击确定后的回调方法
场景 inspinia 前端模板在提示框点击确定后执行回调方法. 实现 //提交后的方法function submitPrint(id){debugger$.ajax({type: 'POST',ur ...
- swig模板 PHP,如何使用nodejs前端模板引擎swig
这次给大家带来如何使用nodejs前端模板引擎swig,使用nodejs前端模板引擎swig的注意事项有哪些,下面就是实战案例,一起来看一下. 相对于jade,我还是更喜欢swig前端模板引擎,jad ...
- springboot前端传参date类型后台处理方式
springboot前端传参date类型后台处理方式 先说结论:建议大家直接使用@JsonFormat,原因如下: 1.针对json格式:在配置文件中加以下配置 spring.jackson.date ...
最新文章
- 60+业内技术专家,9大核心技术专题,AI ProCon倒计时一周!
- 多线程join(加入)
- oracle导入del数据文件,pl/sql,Oracle数据库中,不小心delete数据并递交后如何恢复被删数据...
- :)xception_Xception:认识Xtreme盗梦空间
- linux关闭远程服务器,linux – 远程主机关闭SSH连接
- 干加个偏旁可以变成什么字_面试官:“干”字加一笔,变成什么字?回答王和午字不对...
- 什么样的环境才是最理想的工作环境呢?
- SpringMVC注解@RequestParam解析
- 《About Face 3:交互设计精髓》读书笔记(一)
- python dateutil_python时间处理模块dateutil
- 为什么罗氏线圈不能测直流电流?
- 心灵奇旅最触动我的一段
- UGUI Canvas(画布)详解
- (三)计算机视觉 --SIFT特征匹配、地理标记图像匹配及RANSAC图像拼接
- 【Kubernetes】Kubeadm安装的K8s集群的版本升级过程测试(二)
- [转载]DbHelper的常用数据库类
- 设为主页代码及添加到收藏夹代码大全 1
- 美国北亚利桑那大学计算机专业排名,北亚利桑那大学排名 综合排名和专业排名介绍...
- 【恩墨学院】京东618大促网关承载十亿调用量背后的架构实践
- 随机森林预测财务报表是否舞弊
热门文章
- 武汉大学IGS数据中心网站的下载方法
- -1和255有什么区别?
- 记录一个bug 关于 java 解压缩包 写入本地报错 :java.io.FileNotFoundException(系统找不到指定的路径。)
- Injection简单使用
- matlab矩阵错位相加,矩阵的旋转和相加——数组实现
- [20160806]ROWDEPENDENCIES.txt
- 创建python虚拟环境,安装Django
- QQ视频聊天,画面顺时针倒转90度问题(MT8163 Android 9.0平台)
- 微软数字签名工具--SigCheck的应用
- wifi共享精灵 强大的网络伴侣