Spring Boot☞ 使用freemarker模板引擎渲染web视图
效果图
代码
package com.wls.integrateplugs.hello.controller; /**
* Created by wls on 2017/8/24.
*/
import java.util.Locale;
import java.util.UUID; import javax.servlet.http.HttpSession; import com.sun.org.apache.regexp.internal.RE;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore; @RestController
public class HelloController { @RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello(Locale locale, Model model) {
return "hello world";
} @RequestMapping("/helloWorld")
public String index() {
return "Hello World";
} /**
* 使用@RestController时,则使用ModelAndView显示页面
* @param map
* @return
*/
@ApiIgnore
@RequestMapping(value = "/helloThymeleaf",method = RequestMethod.GET)
public ModelAndView indexThymeleaf(ModelMap map) {
ModelAndView mv = new ModelAndView("indexThymeleaf");
map.addAttribute("name","王老师");
map.addAttribute("host", "http://blog.didispace.com");
return mv;
} @RequestMapping(value = "/helloFreeMarker",method = RequestMethod.GET)
public ModelAndView indexFreeMarker(ModelMap map) {
ModelAndView mv = new ModelAndView("indexFreeMarker");
map.addAttribute("name","王老师");
map.addAttribute("host", "http://blog.didispace.com");
return mv;
} /**
* 共享session
* @param session
* @return
*/
@RequestMapping(value = "/uid",method = RequestMethod.GET)
String uid(HttpSession session) {
UUID uid = (UUID) session.getAttribute("uid");
if (uid == null) {
uid = UUID.randomUUID();
}
session.setAttribute("uid", uid);
return session.getId();
} }
indexFreeMarker.ftl
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
FreeMarker模板引擎
<h1>${host}</h1>
</body>
</html>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
Spring Boot☞ 使用freemarker模板引擎渲染web视图的更多相关文章
- Spring Boot☞ 使用Thymeleaf模板引擎渲染web视图
静态资源访问 在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. 默认配置 Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /s ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- Spring Boot实战:模板引擎
虽然现在很多开发,都采用了前后端完全分离的模式,即后端只提供数据接口,前端通过AJAX请求获取数据,完全不需要用的模板引擎.这种方式的优点在于前后端完全分离,并且随着近几年前端工程化工具和MVC框架的 ...
- Spring Boot2(五):使用Spring Boot结合Thymeleaf模板引擎使用总结
一.Thymeleaf概述 一般来说,常用的模板引擎有JSP.Velocity.Freemarker.Thymeleaf . SpringBoot推荐的 Thymeleaf – 语法更简单,功能更强大 ...
- Spring Boot整合 Thymeleaf 模板引擎
什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...
- idea 使用spring boot 搭建freemarker模板
一丶新建maven spring boot 项目 新建好了开始使用模板 先看一个目录结构 二丶配置pox.xml <?xml version="1.0" encoding ...
- Spring Boot整合Thymeleaf模板引擎
什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...
- Spring Boot中使用模板引擎Thymeleaf
一.Thymeleaf简介 Thymeleaf[taɪm lif],百里香叶,是一个流行的模板引擎,该模板引擎采用Java语言开发.Java中常见的模板引擎有Velocity.Freemaker.Th ...
- Spring 学习笔记(十)渲染 Web 视图 (Apache Tilesa 和 Thymeleaf)
使用Apache Tiles视图定义布局 为了在Spring中使用Tiles,需要配置几个bean.我们需要一个TilesConfigurer bean,它会负责定位和加载Tile定义并协调生成Til ...
随机推荐
- python 生成器和生成器表达式
1.生成器 生成器的本质就是迭代器 生成器的特点和迭代器一样.取值方式和迭代器一样(__next__(),send():给上一个yield传值) 生成器一般由生成器函数或者生成器表达式来创建 其实就是 ...
- postman断言的方法
1.在test添加断言 2.检查response的body中是否包含字符串: tests["Body matches string"] = responseBody.has(&qu ...
- mysql 存储过程简单学习
转载自:http://blog.chinaunix.net/uid-23302288-id-3785111.html ■存储过程Stored Procedure 存储过程就是保存一系列SQL命令的集合 ...
- 第四章 Kubernetes 架构
4.1 Master节点:Master是大脑,运行如下Daemon服务: API Server(kube-apiserver) API server提供了HTTP/HTTPS RESTful ...
- 【BZOJ】2809: [Apio2012]dispatching(左偏树)
题目 传送门:QWQ 分析 显然是一个资瓷合并的堆 现学了一发左偏树:教程 然后就没了 代码 #include <bits/stdc++.h> #define lc son[x][0] # ...
- c++ 先序构建二叉树
二叉树首先要解决构建问题,才能考虑后续的遍历,这里贴出通过先序构建二叉树,同时包含四种二叉树的遍历方法(先序,中序,后序,逐层) 第一.定义BinaryTreeNode 类 #include < ...
- RAC的时间同步问题
今天在两个节点上面安装RAC,在安装clusterware的时候OUI总是提示失败.查到资料的得知: 特此记录: 需要在在所有的集群节点上设置正确的日期和时间 在安装 Oracle 集群件.数据库以 ...
- Cocos2d-html5帧动画
单独获取plist里面一个文件: cc.SpriteFrameCache.getInstance().addSpriteFrames(s_test_plist); var spriteTest2 = ...
- sql server xml 截断
c#读取 sql生成的xml时,发生阶段. 加,type 解决
- OpenLayers 3 之 地图视图(View)
OpenLayers 3 之 地图视图(View) 初始化一幅地图,必备的三要素之一视图(view),这个对象主要是控制地图与人的交互,如进行缩放,调节分辨率.地图的旋转等控制.也就是说每个 map对 ...