SpringBoot入门:添加FreeMarker支持
2017-03-29 14:46
459 查看
SpringBoot入门-添加FreeMarker支持
Maven配置(pom.xml)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-boot-freemarker</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <properties> <!-- 指定JDK版本,默认是1.6 --> <java.version>1.8</java.version> </properties> <dependencies> <!-- Web支持 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- FreeMarker支持 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> </dependencies> <build> <finalName>spring-boot-freemarker</finalName> </build> </project>
应用配置文件
存放路径:src/main/resources/application.propertiesspring.freemarker.allow-request-override=false spring.freemarker.cache=false spring.freemarker.check-template-location=true spring.freemarker.charset=UTF-8 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=false
Controller类
@Controller public class FreeMarkerController { @RequestMapping("/freemarker") public String hello(Map<String, Object> map) { map.put("name", "FreeMarker"); return "freemarker"; } }
FreeMarker模板文件
存放路径:src/main/resouces/templates/freemarker.ftl<html> <head></head> <body>Hello ${name}</body> </html>
启动类
@SpringBootApplication public class FreemarkerApplication { public static void main(String[] args) { SpringApplication.run(FreemarkerApplication.class, args); } }
测试效果
启动程序后,在浏览器中访问:http://localhost:8080/freemarker返回结果:
Hello FreeMarker
参考文档
《从零开始学Spring Boot》相关文章推荐
- SpringBoot入门:添加JSP支持
- spring boot 添加log4j的支持
- springboot笔记(2)springboot-添加对jsp支持
- SpringBoot添加freemarker+jxl下载数据库记录
- Spring Boot 学习10--添加JSP支持
- Spring Boot 添加JSP支持
- Spring boot 添加jsp支持配置
- springboot添加支持jsp
- (19)Spring Boot 添加JSP支持【从零开始学Spring Boot】
- SpringBoot添加freemarker模板引擎
- spring boot 添加jsp支持注意事项
- 使用Spring Boot开发Web项目(二)之添加HTTPS支持
- 使用Spring Boot开发Web项目(二)之添加HTTPS支持
- SpringBoot学习:添加JSP支持
- spring boot mvc添加对jsp的支持
- Spring Boot 添加JSP支持
- 使用Spring Boot开发Web项目(二)之添加HTTPS支持
- 19. Spring Boot 添加JSP支持【从零开始学Spring Boot】
- spring-boot 添加跨域支持
- 19. Spring Boot 添加JSP支持【从零开始学Spring Boot】