springboot中如何整合freemarker
来源:亿速云
时间:2024-04-11 14:18:11 111浏览 收藏
今日不肯埋头,明日何以抬头!每日一句努力自己的话哈哈~哈喽,今天我将给大家带来一篇《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(Mapmap){ String dataUrl = "http://localhost:31001/cms/config/getmodel/5a791725dd573c3574ee333f"; ResponseEntity
今天带大家了解了的相关知识,希望对你有所帮助;关于文章的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
声明:本文转载于:亿速云 如有侵犯,请联系study_golang@163.com删除