您的位置:首页 > 编程语言 > Java开发

微服务,微架构[十一]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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐