微服务,微架构[十一]springboot模板页面velocity

来源:互联网 发布:java互联网开发框架 编辑:程序博客网 时间:2024/05/29 04:22

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**/@Controllerpublic 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>