freemarker

spring-boot集成Freemarker开发

流过昼夜 提交于 2019-12-03 18:59:01
1.该demo功能 http://localhost/system/login展示后台发布新闻列表 http://localhost/前端Freemark模板展示 中间用到了Mysql, Mybatis, druid;可以参考spring-boot相关的demo 2.Pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> 3.项目启动 @SpringBootApplication @MapperScan(basePackages="com.lance.freemaker.mapper") public class SimpleApplication { public static void main(String[] args) { SpringApplication.run(SimpleApplication.class, args); } } @Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter{ @Override public void addInterceptors

web项目PDF导出---freemarker 与 ITextRenderer--加页码

南笙酒味 提交于 2019-12-03 18:58:50
最近项目中又遇到pdf导出的需求,以前一直都是用phantomjs-2.1.1-windows.exe插件做的pdf导出,运用插件优点是直接可以把html页面直接转换成pdf导出,缺点是它需要安装,windows、linux、mac等环境下需要的插件安装都不一样,中文字体还需要单独安装;查询了一些文档后就决定采用freemarker 与 ITextRenderer来实现了;偶然间在git看到了 flying saucer 项目;发现思路基本一致就在其基础上开发了(^_^) 。 freemarker 模板能很好的支持html、css样式;但是运用之前需要小小的学习一下freemarker ftl模板的一些固定语法,这对一般的开发者而言应该都没什么难度(^^)。 下面记录一下用到的方法与运用freemarker 与 ITextRenderer过程的一些坑 ftl模板中中文字体显示 ftl模板中静态资源引入 ftl模板中img显示 @RequestMapping( "/createPdf/{corpid}" ) public ResponseEntity<byte[]> createPdf(@PathVariable(value= "corpid" ) String corpid,HttpServletRequest request) throws Exception { Map<

Spring Boot 整合 FreeMarket

自闭症网瘾萝莉.ら 提交于 2019-12-03 18:54:54
官方Demo spring-boot-sample-web-freemarker 依赖的模块 < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-freemarker </ artifactId > </ dependency > 默认加载类路径 templates 目录下的文件 可以在 application.properties 中通过属性 spring.freemarker.template-loader-path 自定义模版文件所在的目录 spring.freemarker.template-loader-path=classpath:/activiti/ //默认前缀为空 spring .freemarker .prefix = //默认后缀为 .ftl spring .freemarker .suffix = .ftl 来源: CSDN 作者: 不务正业的野猴子 链接: https://blog.csdn.net/quan20111992/article/details/80287611

SpringBoot之整合freemarket

青春壹個敷衍的年華 提交于 2019-12-03 18:53:39
SpringBoot整合freemarket 1.pom配置:添加 freemarket 启动器 <!-- spring freemarker 开始 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <!-- spring freemarker 结束 --> 2.springboot中默认的模板引擎都是放在 src/main/resource/templaters/ 目录下 此处我建立一个 templaters 文件夹,并建立一个 flt 的文件里,用于存放 freemarket 的模板文件。 3,遍写模板文件,freemarket的文件后缀为 .ftl <table class="table table-bordered"> <tr><td>姓名</td></tr> <#list arr as i> <tr><td>${ i }</td></tr> </#list> </table> 4.编写控制器 @Controller public class FreemarkerController { @RequestMapping("/freemarker") public

Checking Spring security roles and logged username in Freemarker template

淺唱寂寞╮ 提交于 2019-12-03 15:37:44
Does anyone know the freemarker tags to check spring security roles and username in freemarker file? I found from couple of resources on the web that the following code would print the logged in username. But it is not printing the username, instead it is printing just "logged in as" <security:authorize access="isAuthenticated()"> logged in as <security:authentication property="principal.username" /> </security:authorize> Also checking the roles in Freemarker file is also not working. Has anyone done it before? The following should work: step 1: Include Spring security tag library on top of

spring boot使用freemarker模版整合spring Data JPA

半世苍凉 提交于 2019-12-03 15:26:50
目录结构 第一步:在pom.xml文件中添加依赖 <!--模板依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <!-- springBoot JPA的起步依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> 第二步:在application.properties中配置数据源 #DB Configation spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?serverTimezone

Liferay 7 Freemarker Template. staticUtil has evaluated to NULL or missing - Tried to get JournalArticle&#039;s Categories

匿名 (未验证) 提交于 2019-12-03 10:09:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi fellow Liferay'ers, I'm trying to get the categories of a journalArticle with a Freemarker template. I tried this code: <#assign journalArticleId = .vars['reserved-article-id'].data> <#assign journalArticleResourceLocalServiceUtil = staticUtil["com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil"]> <#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil"]> <#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId

Freemarker/Velocity - date manipulation

南笙酒味 提交于 2019-12-03 09:12:41
I have a fairly simple question about these 2 templating engines. I'm trying to make a future/past date, a fixed time from now, e.g. 18 months ago, or tomorrow. I know that it is possible to do this with a java date object inside a velocity/freemarker template (something like $date.add(2,-18) ), but I would like to do this with DateTool or freemarker core. This is something that I see as purely presentational (just think at the default dates you see in flight booking forms), so I can't see any reason why a templating engine shouldn't be able to do this. Is it possible though? If so, how? In

FreeMarker template error: The following has evaluated to null or missing | BUT NOT TRUE

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The error I'm facing is so weird. Everything looks fine, but I get this error when the browser sends the GET request to the server. What I'm trying to do is actually catching the HTTP parameters, save them in an object saved in an ArrayList sending to a Freemarker template. Could you please help me? Thanks a lot. The error: freemarker.log._JULLoggerFactory$JULLogger error SEVERE: Error executing FreeMarker template FreeMarker template error: The following has evaluated to null or missing: ==> item.lat1 [in template "view/result.ftl" at line

how to use messages with freemarker in spring mvc?

强颜欢笑 提交于 2019-12-03 08:40:19
问题 In a .jsp I would use: <fmt:message key="welcome.title"/> to display a message from my messages.properties file. How would I do this with freemarker ? 回答1: Import Spring Macro <#import "/spring.ftl" as spring/> Then <@spring.message "yourMessageKeyGoesHere"/> But you need to register ResourceBundleMessageSource <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages"/> </bean> Keep in mind MessageSource must