freemarker

freemarker 内置函数

自闭症网瘾萝莉.ら 提交于 2019-12-22 11:26:44
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在我们应用 Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚 Freemrker 有没有类似于 Java 一样有相关的类及方法。在本文当中,我将向大家详细的介绍 Freemarke 的内置函数及用法,以便能帮助大家更熟练的应用 Freemarker 完成项目开发。 一、 Sequence 的内置函数 1. sequence?first 返回 sequence 的第一个值。 2. sequence?last 返回 sequence 的最后一个值。 3. sequence?reverse 将 sequence 的现有顺序反转,即倒序排序 4. sequence?size 返回 sequence 的大小 5. sequence?sort 将 sequence 中的对象转化为字符串后顺序排序 6. sequence?sort_by(value) 按 sequence 中对象的属性 value 进行排序 注意: Sequence 不能为 null 。以上方法在我的另一篇博客 Freemarker 中如何遍历 List 有详细的应用,感兴趣的朋友可以参考。 二、 Hash 的内置函数 1. hash?keys 返回 hash 里的所有 key, 返回结果为 sequence 2. hash

Spring with FreeMarker: Could not resolve view with name 'Home' in servlet with name 'MyServlet'

自作多情 提交于 2019-12-22 08:19:07
问题 I am trying to create a very simple integration of FreeMarker and Spring. However, when I run my example, I get an exception: GRAVE: Servlet.service() for servlet MyServlet threw exception javax.servlet.ServletException: Could not resolve view with name 'Home' in servlet with name 'MyServlet' at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1162) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) at org.springframework

Reading ServletOutputStream to String

99封情书 提交于 2019-12-22 06:27:45
问题 I am trying to read the result of FreemarkerView rendering: View view = viewResolver.resolveViewName(viewName, locale); view.render(model, request, mockResponse); To read the result, I have created mockResponse , which encapsulates the HttpServletResponse: public class HttpServletResponseEx extends HttpServletResponseWrapper { ServletOutputStream outputStream; public HttpServletResponseEx(HttpServletResponse response) throws IOException { super(response); outputStream = new

How can I get the first item in a list using free marker?

非 Y 不嫁゛ 提交于 2019-12-22 04:44:12
问题 I have the following code which contains about 12 items but I only need to retrieve the first item. How can I display the first item in my list? My code is: <#list analysttest.rss.channel.item as item> <div> <h3 class="bstitle">${item.title}</h3> <span class="bsauthor">${item.author}</span> <span>${item.pubDate}</span> <p>${item.description}</p> </div> </#list> 回答1: analysttest.rss.channel.item[0] gives the fist item, which you can #assign to a shorther name for convenience. Note that at

Keycloak Remove First Name and Last Name fields on Registration Screen

岁酱吖の 提交于 2019-12-21 20:24:32
问题 In Keycloak we have a created a custom ftl registration theme that has removed the optional first name and last name fields. Our system only requires the user to have an email address and password. However when the user hits enter an error is displayed indicating that the first name and last name need to be entered. In the Keycloak UserModel these fields are optional, and it is also possible to create users via the admin console / api without firstname and lastname. How do we remove these

spring security 3.2.0 csrf token not working in freemarker template

假如想象 提交于 2019-12-21 18:34:46
问题 After uprading to Spring Security 3.2.0 and configuring the xml, the _csrf token is not working. Fundamentals: Spring 4.0.1 Spring Security 3.2.0. Freemarker Template Language Step 1 - the spring security xml configuration: <!-- enable csrf protection via csrf-element --> <sec:http> <!-- --> <sec:csrf token-repository-ref="csrfTokenRepository" /> </sec:http> <!-- rewrite headerName --> <bean id="csrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository">

springMVC配置freemarker

两盒软妹~` 提交于 2019-12-21 15:50:27
这里呢,我首先来说明一下写该篇的目的。 我最近要用到freemarker因此研究了一下这个东西。 先来说说如何配置吧。 1、jar包。地址见下链接。 http://pan.baidu.com/s/1jGOgKPC 其他的几个jar包我就不提供了,毕竟你都搞到springMVC了还不知道需要什么包也说不过去了。 2、在servlet.xml文件中配置freemarker <!-- freemarker的配置 --> <bean id="freemarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/pages/" /> <property name="defaultEncoding" value="utf-8" /> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">10</prop> <prop key="locale">zh_CN</prop> <prop key="datetime_format">yyyy-MM-dd HH:mm:ss

Feemarker writing images to html

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 12:21:19
问题 is there anyway to write image in freemarker instead of giving link as <img src="${pathToPortalImage} Note : cant we use otputstream or something in freemarker ? 回答1: You can embed the image as base64 directly inside the html img tag. To convert an image to base 64 you can use Apache Commons (codec). Here is a solution using Apache Commons IO + Codec (but you can do without if you want): File img = new File("file.png"); byte[] imgBytes = IOUtils.toByteArray(new FileInputStream(img)); byte[]

Passing a List of Objects to Freemarker and then Looping

跟風遠走 提交于 2019-12-20 16:18:10
问题 I've been acquainting myself with FreeMarker, a template engine for Java. I got to the point where I am able to pass an object to the template engine through a Hash Map. That works alright. But as soon as I try to pass any sort of set of multiple objects to FreeMarker it gives me a freemarker.template.TemplateException and complains that it "Expected collection or sequence. jobs evaluated instead to freemarker.template.SimpleHash". From what I understand from reading up on this in the various

Freemarker导出word文档 的一些问题

随声附和 提交于 2019-12-20 11:46:49
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我被图片换行问题给难了好一会儿,我没想到在word中,两个图片标签本身就自带了换行功能,如果要想使图片不换行的话,需要将两个图片放在一个w:p标签中。 明白这一点之前,我花了不少时间去找所谓的换行符,通过beyond compare各种对比不同效果、换行与不换行的图片之间的区别。 这次耐心还是挺足的,不然估计的花更多的时间才能找到答案。 这次要赖自己的英语水平了——通过文档对比其实我早就注意到包含【GoBack】关键字的【w:bookmarkStart】标签了,但我却把它错误理解成了换行符……甚至还在想,为啥我把换行符去掉之后,怎么这个换行标签就从xml中出现了呢……哈哈,现在想来自己真是太可笑。 我要是英语再好一点的话,应该早就意识到,哦,原来两个图片标签本身就自带换行效果,如果想要不换行的话,需要将其写在同一个w:p标签中,并且用被我南辕北辙的误解为换行符的【不换行符】来实现这个效果。 一个好消息是,我已经持续学习英语一个月了,并且会继续坚持一下去。 <w:p w:rsidR="00A644D4" w:rsidRDefault="003E49CE" w:rsidP="001D19BC"> <w:r> <w:rPr> <w:noProof/> </w:rPr> <w:drawing> <wp:inline