微服务,微架构[十一]springboot模板页面velocity
2017-05-30 21:00
337 查看
springboot可以集成很多模板文件来实现访问页面,今天我们主要介绍velocity的集成方式,很多集成模板页面都是大同小异
一、加入依赖pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</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 {
@RequestMapping("/hello")
@ResponseBody
public String hello() {
return "Hello World";
}
@RequestMapping("/")
public String index(ModelMap map) {
map.addAttribute("host", "http://blog.csdn.net/ysl_228");
return "index";
}
}
三、页面内容,默认读取路径是resource/template/index.vm
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
Velocity模板
<h1>${host}</h1>
</body>
</html>
一、加入依赖pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</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 {
@RequestMapping("/hello")
@ResponseBody
public String hello() {
return "Hello World";
}
@RequestMapping("/")
public String index(ModelMap map) {
map.addAttribute("host", "http://blog.csdn.net/ysl_228");
return "index";
}
}
三、页面内容,默认读取路径是resource/template/index.vm
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
Velocity模板
<h1>${host}</h1>
</body>
</html>
相关文章推荐
- 微服务,微架构[十一]springboot模板页面thymeleaf
- SpringBoot系列十一:SpringBoot整合Restful架构(使用 RestTemplate 模版实现 Rest 服务调用、Swagger 集成、动态修改日志级别)
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十九)多数据源配置与使用(1)
- Spring Cloud Spring Boot mybatis分布式微服务云架构(二十三)使用MongoDB数据库(1)
- 基于Spring Boot和Spring Cloud实现微服务架构学习(一)-Spring框架介绍
- 企业分布式微服务云架构技术分享 Spring Cloud + Spring Boot + Mybatis + shiro + RestFul + 微服务
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三十八)使用log4j记录日志
- Spring Cloud Spring Boot mybatis分布式微服务云架构(九)使用Swagger2构建强大的RESTful API文档(1)
- 基于Spring Boot和Spring Cloud实现微服务架构学习(三)-Spring Boot应用
- Spring Cloud Spring Boot mybatis分布式微服务云架构(五)
- Spring Cloud Spring Boot mybatis分布式微服务云架构(六)RESTfu
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十三)
- spring cloud + spring boot + ...分布式微服务云架构
- Spring Cloud Spring Boot mybatis分布式微服务云架构(四)属性配置文件详解(2)
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三)属性配置文件详解(1)