SpringBoot+Maven项目实战(3):整合Freemark模板
2016-11-03 14:52
916 查看
SpringBoot 自动继承了thymeleaf、freemark、velocity三种模板技术,因为我项目中需要用来Freemark模板进行生成Java类所以,就整合了SB+F
1.配置pom文件,引入Freemarker
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
2.配置模板属性(application.properties)
# FREEMARKER (FreeMarkerAutoConfiguration) spring.freemarker.allow-request-override=false spring.freemarker.allow-session-override=false spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.enabled=true spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=true spring.freemarker.prefer-file-system-access=true spring.freemarker.suffix=.ftl spring.freemarker.template-loader-path=classpath:/templates/ spring.freemarker.settings.template_update_delay=0 spring.freemarker.settings.default_encoding=UTF-8 spring.freemarker.settings.classic_compatible=true spring.freemarker.order=1
3.编写Controller mapping
@RequestMapping("/hello/{name}") public String hello(@PathVariable("name") String name, Model model) { model.addAttribute("name", name); model.addAttribute("age","25"); model.addAttribute("sex","man"); model.addAttribute("birth",new Date()); return "hello"; }
4.编写hello.ftl页面模板
<!DOCTYPE html> <html lang="en"> <head> <title>SpringBoot + Freemarker</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> Hello ${name}${age}${sex} <p>${birth?string("yyyy-MM-dd HH:mm:ss.sss")}</p> </body> </html>
5.启动Application、访问hello/{name}
Hello zhangyd25man 2016-10-21 10:51:26.026
相关文章推荐
- SpringBoot+Maven项目实战(6):整合Log4j和Aop,实现简单的日志记录
- maven项目 spring-boot 整合 mybatis 实现查询功能demo
- SpringBoot+Maven项目实战(2):集成SpringBoot
- Springboot整合dubbo构建maven多模块项目(一)- 项目创建和pom.xml中jar包配置
- SpringBoot实战学习(一) Maven安装、Spring搭建项目
- IDEA上搭建maven项目整合springboot+mybatis+shiro
- 05(maven+SSH)网上商城项目实战之spring mybatis整合
- Springboot 多模块 整合 Mybatis maven项目
- SpringBoot+Maven 多模块项目的构建、运行、打包实战
- SpringBoot+Maven项目实战(4):集成Mybatis
- SpringBoot+Maven项目实战(2):集成SpringBoot
- CK1956-2017年最新项目实战Spring Boot视频微服务整合Mybatis
- SpringBoot+Maven项目实战(1):新建Maven项目
- SpringBoot+Maven项目实战(1):新建Maven项目
- SpringBoot创建maven多模块项目实战代码
- 【备忘】2017年最新 项目实战 Spring Boot视频教程 微服务整合Mybatis
- Springboot整合dubbo构建maven多模块项目(三) - 把server分为api(服务接口定义)和server(服务实现)两个子module
- Springboot整合dubbo构建maven多模块项目(四) - 集成mybatis
- CK1956-2017年最新项目实战Spring Boot视频微服务整合Mybatis
- Maven项目中,关于Spring Boot 整合MyBatis时,Service层无法找到mapper接口的问题解决