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

来源:互联网 发布:suse 端口开放 编辑:程序博客网 时间:2024/06/08 23:01

springboot可以集成很多模板文件来实现访问页面,今天我们主要介绍freemarker的集成方式

一、freemarker 依赖jar文件pom.xml配置添加

              <dependency>  

   <groupId>org.springframework.boot</groupId>  
   <artifactId>spring-boot-starter-freemarker</artifactId>  

</dependency>  

二、创建页面文件,默认读取路径templates,扩展名为index.ftl

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8" />    <title></title></head><body>FreeMarker模板引擎<h1>${host}</h1></body></html>



三、访问控制器返回页面内容

/**** @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(Model map) {       map.addAttribute("host", "http://blog.csdn.net/ysl_228");       return "index";   }}

集成很简单,感谢大家的阅读本文


原创粉丝点击