这篇文章将为大家详细讲解有关springboot中怎么整合 freemarker,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联是一家专业提供怀宁企业网站建设,专注与成都网站建设、成都做网站、H5高端网站建设、小程序制作等业务。10年已为怀宁众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
依赖
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 关于springboot中怎么整合 freemarker就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。