freemarker

Freemarker - access value at a particular key in map

瘦欲@ 提交于 2019-12-01 17:58:56
I have Map variable in my Freemarker template. How can I fetch a value at a particular key in the map, as we do in Java ( map.get(<key>) ). I know how to iterate through keys and values of a map in a FTL. But I want a solution without iteration, on the lines of Java get() method of Map interface. map[dynamicKey] or map.staticKey if the key is a string. Due to historical limitations, if the key isn't a string, map?api.get(nonStringKey) . 来源: https://stackoverflow.com/questions/39248560/freemarker-access-value-at-a-particular-key-in-map

Freemarker - access value at a particular key in map

淺唱寂寞╮ 提交于 2019-12-01 17:29:08
问题 I have Map variable in my Freemarker template. How can I fetch a value at a particular key in the map, as we do in Java ( map.get(<key>) ). I know how to iterate through keys and values of a map in a FTL. But I want a solution without iteration, on the lines of Java get() method of Map interface. 回答1: map[dynamicKey] or map.staticKey if the key is a string. Due to historical limitations, if the key isn't a string, map?api.get(nonStringKey) . 来源: https://stackoverflow.com/questions/39248560

springboot整合freemarker模板

被刻印的时光 ゝ 提交于 2019-12-01 12:22:19
Freemarker作用于表现层,能更好的实现mvc分离。 1、首先,在pom文件里加入freemarker依赖 <!-- 整合freemarker --> <dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> 2、在配置文件application.properties中加入freemarker配置 # freemarker静态资源配置 # 设定ftl文件路径 spring.freemarker.tempalte-loader-path=classpath:/templates # 关闭缓存,及时刷新,上线生产环境需要修改为true spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose

Spring Boot2 系列教程(十)Spring Boot 整合 Freemarker

那年仲夏 提交于 2019-12-01 11:45:37
今天来聊聊 Spring Boot 整合 Freemarker。 Freemarker 简介 这是一个相当老牌的开源的免费的模版引擎。通过 Freemarker 模版,我们可以将数据渲染成 HTML 网页、电子邮件、配置文件以及源代码等。Freemarker 不是面向最终用户的,而是一个 Java 类库,我们可以将之作为一个普通的组件嵌入到我们的产品中。 来看一张来自 Freemarker 官网的图片: 可以看到,Freemarker 可以将模版和数据渲染成 HTML 。 Freemarker 模版后缀为 .ftl (FreeMarker Template Language)。FTL 是一种简单的、专用的语言,它不是像 Java 那样成熟的编程语言。在模板中,你可以专注于如何展现数据, 而在模板之外可以专注于要展示什么数据。 好了,这是一个简单的介绍,接下来我们来看看 Freemarker 和 Spring Boot 的一个整合操作。 实践 在 SSM 中整合 Freemarker ,所有的配置文件加起来,前前后后大约在 50 行左右,Spring Boot 中要几行配置呢? 0 行! 1.创建工程 首先创建一个 Spring Boot 工程,引入 Freemarker 依赖,如下图: <dependency> <groupId>org.springframework.boot<

FreeMarker如何生成静态页面

回眸只為那壹抹淺笑 提交于 2019-12-01 10:14:02
一、 FreeMarker 生成静态页原理 众所周知,FreeMarker适合于作为Web应用的表现层,那么我们就把把页面中所需要的样式放入FreeMarker文件中,然后将页面所需要的数据动态绑定,并放入Map中,通过调用FreeMarker模板文件解析类process()方法完成静态页面的生成。了解了上面的原理,接下来 四夕 就一步步带您实现FreeMarker生成静态页面。 二、 创建FreeMarker模板文件user.ftl。 User.ftl <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv=Content-Type content="text/html; charset=utf-8"> <title>user.ftl</title> </head> <body> ${user.userName} ${user.userPassword} </body> </html> 三、 创建FreeMarker模板文件解析器类FreeMarkertUtil FreeMarkertUtil.java //省略包的导入 Public class FreeMarkerUtil{ //templatePath模板文件存放路径 /

How to customize number format in freemarker?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 06:31:23
I am using freemarker and trying to display numbers in this format: $3,343,434.00 for example. This was easily taken care of by using ${total?string.currency} (assuming "total" is some number). However, when I have negative numbers, it's showing them like this: ($343.34) instead of this: -$343.34 . I need the negative sign instead of the parenthesis. Is there a way I could customize the formatting so it does everything that the string.currency did but replace the negative value behavior? I am relatively new to freemarker, so detailed responses are appreciated! You can also try ?string(",##0.00

How to customize number format in freemarker?

谁都会走 提交于 2019-12-01 05:52:11
问题 I am using freemarker and trying to display numbers in this format: $3,343,434.00 for example. This was easily taken care of by using ${total?string.currency} (assuming "total" is some number). However, when I have negative numbers, it's showing them like this: ($343.34) instead of this: -$343.34 . I need the negative sign instead of the parenthesis. Is there a way I could customize the formatting so it does everything that the string.currency did but replace the negative value behavior? I am

Freemarker encoding - question marks in the place of accented characters

一个人想着一个人 提交于 2019-12-01 04:51:58
I am trying to print accented characters with Freemarker, but in the place of accented characters, I get only question marks. I have verified, that following statement holds: "UTF-8" == Environment.getCurrentEnvironment().getConfiguration().getDefaultEncoding() I can easily see, that the accented characters are correctly held in the variable before giving it to the template. My freemarker context can be found here: https://gist.github.com/1975239 For instance instead of: Jedinečný živý koncert, kde nejen, že uslyšíte, ale i uvidíte splynutí metalové kapely s padesátičlenným orchestrem včetně.

How to make Netbeans' templates that creates more than 1 file?

柔情痞子 提交于 2019-12-01 04:30:58
One of the most awesome features of Netbeans is to generate code using some FreeMarker templates. I have some questions about it, I hope someone here can help me. How can I make a template on Netbeans that generates more than just 1 file? For example, I use the "JSF Pages From Entity Beans" wizard to generate CRUD files . So it creates automatically 4 files for each entity I have: - Create.xhtml - Edit.xhtml - List.xhtml - View.xhtml This is very useful, because you often needs to create, edit, list or view some records from your database. So I know I can edit each template individually by

Freemarker encoding - question marks in the place of accented characters

本秂侑毒 提交于 2019-12-01 02:33:49
问题 I am trying to print accented characters with Freemarker, but in the place of accented characters, I get only question marks. I have verified, that following statement holds: "UTF-8" == Environment.getCurrentEnvironment().getConfiguration().getDefaultEncoding() I can easily see, that the accented characters are correctly held in the variable before giving it to the template. My freemarker context can be found here: https://gist.github.com/1975239 For instance instead of: Jedinečný živý