从0开始学习SpringCould(4)--SpringBoot 集成freemarker
来源:互联网 发布:mac上安装jmeter 编辑:程序博客网 时间:2024/06/06 02:17
前面几篇已经介绍过SpringBoot的基本使用和配置
本篇来介绍下 使用SpringBoot和freemarker集成使用
一、添加maven依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId></dependency>
二、application.yml中添加freemarker配置
spring: freemarker: # freemarker配置 suffix: .ftl check-template-location: true # 是否缓存 defaultEncoding: UTF-8 templateLoaderPath: classpath:/demo # ftl所在路径 content-type: text/html request-context-attribute: request mvc: static-path-pattern: /static/** # 静态文件所在路径
项目路径如图:
简单说明下,webapp目录如果不存在,需要手动创建。
static–用于存放css、images、js等静态文件
demo–用于存放ftl文件
三、新建index.ftl文件
<body>code:${code!''}<br>name:${name!''}</body>
四、编写controller
@GetMapping("/index")public String index(ModelMap modelMap, @RequestParam String code){ modelMap.put("code",code); modelMap.put("name","和讯"); return "index";}
五、运行
特别说明,在运行前需要在pom文件中增加项目结构的配置,不然webapp路径可能不能被编译。
配置如下:
<build> <resources> <resource> <directory>src/main/webapp</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources></build>
启动应用
访问:
http://localhost:9000/demo/index?code=hexun
SpringBoot集成freemarker 到此完成,主要引入一个依赖包,配置yml文件即可。
本篇结束,谢谢!
更多内容请关注微信公众号:
阅读全文
0 0
- 从0开始学习SpringCould(4)--SpringBoot 集成freemarker
- 从0开始学习SpringCould(6)--SpringBoot 集成swagger2
- 从0开始学习SpringCould(5)--SpringBoot 集成Mybatis使用Druid数据源
- 从0开始学习SpringCould(1)--SpringBoot项目搭建
- 从0开始学习SpringCould(3)--SpringBoot 定时任务
- 从0开始学习SpringCould(2)--SpringBoot yml简单配置
- 从0开始学习SpringCould(7)--SpringBoot 多环境配置
- 从0开始学习SpringCould(8)--SpringBoot 分环境读取配置文件
- 从0开始学习SpringCould(9)--Eureka 服务注册发现
- 从今天开始学习springboot--
- springboot 集成freemarker
- 从0开始学习SpringBoot-第1天
- 从0开始学习SpringBoot-第2天
- 从0开始学习SpringBoot-第3天
- springcould学习(二)之eureka
- springboot采用FreeMarker模板集成应用
- springboot +nginx +freemarker 模板的简单集成
- SpringBoot自我整理学习2(springboot集成Druid)
- 孤儿进程与僵尸进程[总结]
- Eureka 源码解析 —— EndPoint 与 解析器
- springboot-jpa-thymeleaf
- Js实现unicode 中文互转
- 一台电脑运行多个tomcat方法
- 从0开始学习SpringCould(4)--SpringBoot 集成freemarker
- Windows下DATA目录的迁移
- ubuntu中如何用chrome浏览器播放本地flash文件
- gradle.properties的使用教程
- 深入理解WeakHashmap
- Less is more
- MapReduce进阶,函数运行机制以及逻辑详解
- Remote Configure
- Python入手(二)