微服务,微架构[十一]springboot模板页面thymeleaf
2017-05-30 21:05
465 查看
springboot可以集成很多模板文件来实现访问页面,今天我们主要介绍thymeleaf的集成方式,很多集成模板页面都是大同小异,也是springboot推荐使用的页面方式
一、加入依赖pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、控制器访问页面
package com.didispace.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
* @author e生态
* @version 1.0.0
* @blog http://blog.csdn.net/ysl_228 *
*/
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
@RequestMapping("/")
public String index(ModelMap map) {
map.addAttribute("host", "http://blog.csdn.net/ysl_228");
map.addAttribute("test", "1234");
return "index";
}
@RequestMapping("/mvc")
public String index(Model model) {
model.addAttribute("host", "http://blog.csdn.net/ysl_228");
model.addAttribute("test", "1234");
return "mvc";
}
}
三、访问页面,默认资源访问目录resource/template/index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>
一、加入依赖pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、控制器访问页面
package com.didispace.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
* @author e生态
* @version 1.0.0
* @blog http://blog.csdn.net/ysl_228 *
*/
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
@RequestMapping("/")
public String index(ModelMap map) {
map.addAttribute("host", "http://blog.csdn.net/ysl_228");
map.addAttribute("test", "1234");
return "index";
}
@RequestMapping("/mvc")
public String index(Model model) {
model.addAttribute("host", "http://blog.csdn.net/ysl_228");
model.addAttribute("test", "1234");
return "mvc";
}
}
三、访问页面,默认资源访问目录resource/template/index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>
相关文章推荐
- 微服务,微架构[十一]springboot模板页面velocity
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- springboot 常用两种图形形式(thymeleaf模板,jsp页面)
- SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装
- springboot-10-前端页面整合, thymeleaf, freemarker, jsp 模板使用
- springboot如何使用thymeleaf模板访问html页面
- [spring boot] 用 thymeleaf模板开发html页面
- springboot 使用 thymeleaf 模板引擎。在页面写隐藏域接收后台的值。在页面进行对话框提示。
- SpringBoot系列十一:SpringBoot整合Restful架构(使用 RestTemplate 模版实现 Rest 服务调用、Swagger 集成、动态修改日志级别)
- springboot开发日志(4): thymeleaf模板 自定义404和500页面
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三十九)对log4j进行多环境不同日志级别的控制
- Spring Cloud Spring Boot mybatis分布式微服务云架构(四十三)使用log4j实现http请求日志入mongodb(2)
- 基于Spring Boot和Spring Cloud实现微服务架构学习(六)-Docker应用
- 访问不存在的Thymeleaf 资源时使页面转向 404,而不是500 (Spring Boot)
- 基于Spring Boot和Spring Cloud实现微服务架构学习(二)-Spring Boot总结
- SpringBoot整合thymeleaf模板
- (18)使用模板(thymeleaf-freemarker)【从零开始学Spring Boot】
- springboot 整合thymeleaf 模板