velocity

Spring MVC整合Velocity

我只是一个虾纸丫 提交于 2020-01-09 06:20:18
Velocity模板(VM)语言介绍 Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。 当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人 员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。Velocity将java代码从web页面中分离出来,这样为web站点的长 期维护提供了便利,同时也为我们在JSP和PHP之外又提供了一种可选的方案。 Velocity现在应用非常广泛,现在尝试将SpringMVC项目与Velocity整合。 整合过程 采用以前整合的[SpringMVC项目]。 主要涉及改变的文件: pom.xml(引入velocity的jar包) spring-mvc.xml(视图配置,配置velocity) velocity.properties(velocity配置文件) (1)加入dependency <!-- Velocity模板 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1

模板引擎 Velocity

强颜欢笑 提交于 2020-01-09 06:19:24
一直以来开发web的页面都是jsp+jstl+EL表达式。也没遇到什么问题,只是偶尔会禁不住在jsp页面上写上两行java代码,些许影响美观。 听说velocity这个模版很不错。oschina也是用的这个。于是花了些时间学习一下。 很多内容velocity的 官网 上面都说得听清楚了。这里说下web开发方面的。 想用velocity代替jsp其实很简单。先在官网的下载页面下载必须的jar包,分别是 velocity-1.7.zip 和 velocity-tools-2.0.zip 。 在velocity-tools-2.0.zip中有个官方例子,估计看完之后大家都会了。这里简单说下。 首先在web.xml中增加velocity的配置。 <servlet> <servlet-name>velocity</servlet-name> <servlet-class>org.apache.velocity.tools.view.VelocityViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> 添加一个处理vm后缀文件的servlet

框架升级填坑总结

眉间皱痕 提交于 2020-01-08 18:20:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 因公司业务发展,将jdk1.6升级至1.8,tomcat6升级至8。因老项目使用struts2.3.20版本,使用velocity模板渲染,需针对此框架整体升级至struts2.5.x,spring4.x。 注: struts2.5.x适用jdk1.7及以上。 1、更新项目maven包。struts2-core,struts2-json-plugin,struts2-spring-plugin及其余引用版本。删除原低版本引用,例如 :xwork-core ( 2.5版本 struts内置引用了新版 ),保证只有单一新版,防止冲突。 2、修改web.xml。删掉标红的ng. 。 <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher. ng. filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> 3、修改struts.xml文件头部信息标红部位,修改为新的大版本数值,此处使用2.5.x,因此为2.5 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD

【创意编程】弹簧震荡

你说的曾经没有我的故事 提交于 2020-01-06 20:29:32
不知道这一章写什么。 前面的写累了,这个没有心思想了,就写一个简单的弹簧和小球的模拟吧。 结果是这样的: 它的实现也非常清晰可见。把小球和弹簧分别考虑,小球的运动按照速度、加速度的不同其实可以分为四个阶段:自由下落阶段、接触到弹簧之后受到弹力而减速的阶段、速度减为零之后受到弹簧向上的弹力加速上升的阶段、离开弹簧之后的减速运动。 我们先什么都不要管,定义一个小球和一个弹簧: 由于我们要求弹簧是可以压缩的,显然我们每一帧重新绘制它是不现实的。我们需要把弹簧首先做成一个固定的、可以调整高度的形状。我们使用PShape类。我们将仅仅通过一个可变的长度lenght的值来构造一个弹簧。由于我们弹簧的高度是不停地变化的,所以这样做是必要的,能够允许我们在弹簧长度变化的时候仅向一个弹簧绘图函数传入一个长度作为参数来生成一个我们需要的弹簧。 PShape spring ; 构造弹簧: void drawSpring ( PVector position , int springLength ) { stroke ( 0 ) ; strokeWeight ( 2 ) ; noFill ( ) ; pushMatrix ( ) ; translate ( position . x , position . y ) ; beginShape ( ) ; vertex ( - 25 , 0 ) ;

Access Velocity Variable in JavaScript File

别说谁变了你拦得住时间么 提交于 2020-01-06 15:49:12
问题 In Velocity I set a variable like this: #at ($page.config) #set ($zip = $helper.xssSafeString($url.param("zip"))) #end Now I want to access the value of $zip in a JavaScript file that is included like this: #at ($page.body) <script type='text/javascript' src='/javascript/main.js'></script> //... #end In the main.js file I alredy tried the following solutions that I found for example here, but it either detects wrong Syntax or just returns the string "${zip}" as value: var zip = ${zip}; var

Adding folder to classpath in Velocity using Spring framework

丶灬走出姿态 提交于 2020-01-06 14:18:30
问题 How can I add an entire folder to Velocity and use the files inside as resource bundles? Currently in my velocity.xml I have this code: <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="parentMessageSource"> <ref bean="globMessageSource"/> </property> <property name="basenames"> <list> <value>classpath:/WEB-INF/i18n</value> <value>/WEB-INF/templates/velocity/my_vm_template</value> </list> </bean> I need to add i18n

Setting dynamic velocity properties for archetype maven projects

馋奶兔 提交于 2020-01-06 05:26:16
问题 I am creating an archetype and want to create a project wide available property containing things like the current date and an all lower case variant of the artifact id. I found the following post on Stackoverflow, that shows how it normally should be possible. I tried adding this to the archetype-metadata.xml like so: ... <requiredProperty key="artifactIdLower"> <defaultValue>${artifactId.toLowerCase()}</defaultValue> </requiredProperty> <requiredProperty key="ldt"> <defaultValue>${package

Velocity Template Language: How to import EscapeTool

自闭症网瘾萝莉.ら 提交于 2020-01-06 04:47:04
问题 I am trying to use unurl for my mapping template. $url -> hello here & there $esc.url($url) -> hello+here+%26+there $esc.unurl($esc.url($url)) -> hello here & there I wrote the following mapping template, but $esc.unurl([...]) doesn't work. I couldn't figure out how to fix it. One reason might be that I am missing an import, but I don't know how to import the EscapeTool properly. #set($httpPost = $input.path('$').split("&")) { #foreach( $kvPair in $httpPost ) #set($kvTokenised = $kvPair.split

How to iterate nested map in velocity template?

会有一股神秘感。 提交于 2020-01-05 07:16:58
问题 How to iterate nested map in velocity template? I have HashMap<String, HashMap<String, HashMap<String, List<MealPlanGroup>>>> termPlans=new HashMap<String, HashMap<String, HashMap<String, List<MealPlanGroup>>>>(); this map i filled data in java and render to html page but not able to iterate on html page 回答1: Given that you have that scary variable bound to termPlans variable inside a template, you could do the following: #foreach( $level1 in $termPlans ) <!-- Iterating over the values of the

How to embed images into template HTML Velocity?

ぐ巨炮叔叔 提交于 2020-01-05 03:25:12
问题 How to embed images into velocity html template so the recipient can read it without opening the file? I am following the instructions at: http://sengopal.github.io/blog/blog/java-mail-using-velocity-templates.html This is my code: public class SendEmailVelocity { public static void main(String[] args) { final String username = Contants.myEmail; final String password = Contants.myPass; final String toMailRecipient = Contants.mailRecipient; Properties props = new Properties(); props.put("mail