springboot中如何整合freemarker
来源:亿速云
2024-04-11 14:18:11
0浏览
收藏
今日不肯埋头,明日何以抬头!每日一句努力自己的话哈哈~哈喽,今天我将给大家带来一篇《springboot中如何整合freemarker》,主要内容是讲解等等,感兴趣的朋友可以收藏或者有更好的建议在评论提出,我都会认真看的!大家一起进步,一起学习!
依赖
org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.boot spring-boot-starter-freemarker org.projectlombok lombok com.squareup.okhttp3 okhttp 3.9.1 commons-io commons-io 2.6 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test
application.yml
application 参数路径
server: port: 8001 spring: application: name: test-freemarker freemarker: cache: false settings: template_update_delay: 0 template-loader-path: classpath:/templates/
启动类
@SpringBootApplication
public class FreemarkerApplication {
public static void main(String[] args) {
SpringApplication.run(FreemarkerApplication.class, args);
}
@Bean
public RestTemplate restTemplate(){
return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
}
}模板文件
| 序号 | 姓名 | 年龄 | 金钱 | 出生日期 |
| ${stu_index} | #if> >${stu.name} | #if>>${stu.age} | ${stu.money} | ${stu.birthday?date},${stu.birthday?time},${stu.birthday?string("yyyy年MM月dd日")} |
Title <#if model??> <#list model as item> #list> #if>
Controller
package com.mozq.springboot.freemarker.controller;
import com.mozq.springboot.freemarker.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;
import java.util.*;
@Controller //注意不要使用 @RestController
@RequestMapping("/freemarker")
public class FreeMarkerController {
@Autowired
private RestTemplate restTemplate;
@RequestMapping("/banner")
public String banner(Map map){
String dataUrl = "http://localhost:31001/cms/config/getmodel/5a791725dd573c3574ee333f";
ResponseEntity 今天带大家了解了的相关知识,希望对你有所帮助;关于文章的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
版本声明
本文转载于:亿速云 如有侵犯,请联系study_golang@163.com删除
PHP 函数惰性求值:优化性能并节省内存
- 上一篇
- PHP 函数惰性求值:优化性能并节省内存
- 下一篇
- 苹果iOS 17.4.1内部测试曝光,或本周下周亮相
查看更多
最新文章
-
- 文章 · java教程 | 1星期前 | map · 并发安全 · 缓存设计 · Java教程 · java optional concurrenthashmap computeIfAbsent Map缓存
- Java computeIfAbsent 缓存初始化实战:少写判断、避开空值和并发坑
- 236浏览 收藏
-
- 文章 · java教程 | 1星期前 | Java · 异步编程 · 后端开发 · CompletableFuture · 接口聚合 · java 结果合并 completablefuture 并行调用 超时兜底
- Java CompletableFuture 多接口聚合完整流程:并行调用、超时兜底和结果合并
- 428浏览 收藏
-
- 文章 · java教程 | 1星期前 | Java · 线程安全 · DateTimeFormatter · 日期处理 · 并发问题 · java 线程安全 日期格式化 threadlocal SimpleDateFormat DateTimeFormatter
- Java SimpleDateFormat 日期偶发错乱怎么办:从共享实例到线程安全一步步排查
- 481浏览 收藏
-
- 文章 · java教程 | 2星期前 | http接口 · httpclient · Java教程 · 接口调试 · 超时处理 · java 接口调用 httpclient 超时控制 状态码 响应体
- Java HttpClient 调接口实战:超时、状态码和响应体这样处理
- 224浏览 收藏
-
- 文章 · java教程 | 2星期前 | 时间处理 · instant · Java教程 · 时区转换 · DateTimeFormatter · java DateTimeFormatter java.time 时区处理 ZoneId INSTANT
- Java 时间与时区处理实战:Instant、ZoneId 和 DateTimeFormatter 怎么配
- 461浏览 收藏
-
- 文章 · java教程 | 2星期前 | Java · Stream · 集合统计 · 分组聚合 · Collectors · java Stream Collectors groupingBy counting summarizingInt
- Java Stream 分组统计实战:groupingBy、counting 和 summarizingInt 怎么用
- 478浏览 收藏

