前几天发现了一个问题,用set指令给一个变量赋值,如果一开始那个变量有值,然后赋值为null,则赋值不起作用.
比如如下代码
public class Bar {
public String getBar() {
return "hello";
}
public String getFoo() {
return null;
}
}
#set($v=$bar.bar)
$v
#set($v=$bar.foo)
$v
产生输出为
hello
hello
文档上说
引用
If the RHS is a property or method reference that evaluates to null, it will not be assigned to the LHS. Depending on how Velocity is configured, it is usually not possible to remove an existing reference from the context via this mechanism. (Note that this can be permitted by changing one of the Velocity configuration properties).
需要在配置文件中设置directive.set.null.allowed = true才行
或者
#set($v="")
#set($v=$bar.bar)
$v
#set($v="")
#set($v=$bar.foo)
$v
顺便吐槽下velocity的文档,
Note that this can be permitted by changing one of the Velocity configuration properties
你就不能顺便说下改哪个property?
分享到:
相关推荐
在使用velocity作为视图层时候,经常会碰到为空的判断,这里整理了velocity为空判断
#set($name = "hello") 说明:velocity中变量是弱类型的。 当使用#set 指令时,括在双引号中的字面字符串将解析和重新解释,如下所示: #set($directoryRoot = "www" ) #set($templateName = "index.vm" ) #set($...
Velocity是一个基于java的模板引擎(template engine...Velocity也可以为Turbine web开发架构提供模板服务(template service)。Velocity+Turbine提供一个模板服务的方式允许一个web应用以一个真正的MVC模型进行开发。
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
此demo包涵了velocity的两种应用方式:一、用velocity模板生成静态页面(不限制,任何页面都可以包括动态页面);二、直接调用vm当做动态页面应用(和jsp应用方式一个原理)
Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity
velocity 2.0 包需要的 jar 包 官方下载的,测试过了,可以运行 Demo 网上都有,关键几行代码: // ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file"); // 按文件加载 // ve.init(); // Template t = ...
Velocity 和 FreeMarker区别 对于大部分的应用来说,使用 FreeMarker 比 Velocity 更简单,因为 Velocity 还必须编写一些自定义的
Velocity教程
打开网址:http://www.web-tag.net/all_17.htm 就是velocity标签大全 、教程 或下载CHM格式帮助文档
本课程从velocity engine也就是velocity引擎开始, 先讲解velocity的基本使用以及基础语法 , 然后再讲解velocity 的进阶内容velocity Tools , 以及velocity作为web项目的视图改如何使用 , 每一部分都会有一个综合案例...
velocity 电子书velocity 电子书velocity 电子书
Velocity入门教程,语法,Velocity布局,Spring框架集成Velocity
Velocity是一个基于java的模板引擎(template engine...Velocity也可以为Turbine web开发架构提供模板服务(template service)。Velocity+Turbine提供一个模板服务的方式允许一个web应用以一个真正的MVC模型进行开发。
Velocity 是一个基于Java的模版引擎。它允许web 页面设计者引用...这个项目完成后,Velocity将为Turbine web 应用程序框架提供模板服务。Velocity+Turbine 方案提供的模板服务将允许web 应用按真正的mvc模式进行开发。
velocity+springmvc+spring+mybaitsg整合案例 用户管理 带sql ,亲自整合调试,没有问题! /* SQLyog Ultimate v8.32 MySQL - 5.6.19 : Database - test ******************************************************...
关于velocity的学习资料,velocity教程和velocity用户手册
赠送jar包:velocity-engine-core-2.3.jar; 赠送原API文档:velocity-engine-core-2.3-javadoc.jar; 赠送源代码:velocity-engine-core-2.3-sources.jar; 赠送Maven依赖信息文件:velocity-engine-core-2.3.pom;...
Velocity是一个基于java的模板引擎(template engine...Velocity也可以为Turbine web开发架构提供模板服务(template service)。Velocity+Turbine提供一个模板服务的方式允许一个web应用以一个真正的MVC模型进行开发。
velocity中文文档 教程 velocity中文文档 教程 velocity中文文档 教程