zoukankan      html  css  js  c++  java
  • NVelocity系列 → NVelocity配置详解

    在VelocityEngine初始化前,可以通过ExtendedProperties配置NVelocity的运行环境参数,当执行VelocityEngine的Init(ExtendedProperties)后,NVelocity会合并自定义配置和默认配置。NVelocity在NVelocity.Runtime.RuntimeConstants中定义了默认配置项的名称,在内嵌资源文件NVelocity.Runtime.Defaults.nvelocity.properties中定义了所有默认配置项的值。下面列出一些常用配置:

    模板编码:

    input.encoding=ISO-8859-1     //模板输入编码
    output.encoding=ISO-8859-1  //模板输出编码

    #foreach配置

    directive.foreach.counter.name = velocityCount     //计数器名称
    directive.foreach.counter.initial.value = 1               //计数器初始值
    directive.foreach.maxloops = -1                           //最大循环次数,-1为默认不限制 directive.foreach.iterator.name = velocityHasNex    //迭代器名称

    #set配置

    directive.set.null.allowed = false     //是否可设置空值

    #include配置

    directive.include.output.errormsg.start = <!-- include error :     //错误信息提示开始字符串
    directive.include.output.errormsg.end   =  see error log -->      //错误信息提示结束字符串

    #parse配置

    directive.parse.max.depth = 10     //解析深度

    模板加载器配置

    resource.loader = file     //模板加载器类型,默认为文件,可定义多个

    file.resource.loader.description = Velocity File Resource Loader     //加载器描述
    file.resource.loader.class = NVelocity.Runtime.Resource.Loader.FileResourceLoader     //加载器类名称
    file.resource.loader.path = .            //模板路径
    file.resource.loader.cache = false     //是否启用模板缓存
    file.resource.loader.modificationCheckInterval = 2     //检查模板更改时间间隔

    宏配置

    velocimacro.permissions.allow.inline = true                              //是否可以行内定义
    velocimacro.permissions.allow.inline.to.replace.global = false     //是否可以用行内定义代替全局定义
    velocimacro.permissions.allow.inline.local.scope = false             //行内定义是否只用于局部

    velocimacro.context.localscope = false                                    //宏上下文是否只用于局部
    velocimacro.max.depth = 20                                                  //解析深度

    velocimacro.arguments.strict = false                                       //宏参数是否启用严格模式

    资源管理器配置

    resource.manager.class = NVelocity.Runtime.Resource.ResourceManagerImpl          //管理器类名称
    resource.manager.cache.class = NVelocity.Runtime.Resource.ResourceCacheImpl     //缓存器类名称

    解析器池配置

    parser.pool.class = NVelocity.Runtime.ParserPoolImpl     //解析池类名称
    parser.pool.size = 40                                                  //初始大小

    #evaluate配置

    directive.evaluate.context.class = NVelocity.VelocityContext     //上下问类名称

    可插入introspector配置

    runtime.introspector.uberspect = NVelocity.Util.Introspection.UberspectImpl     //默认introspector类名称
     
    在NVelocity中有的配置是可以定义多个的,比如资源加载器。注意一点在传入的实现类名称一定要采用:class fullname;assembly name格式,比如自定义了一个资源加载器EasyNet.Mvc.AssemblyResourceLoader,程序集名称为EasyNet.Mvc,那么应该如下示例定义:
    VelocityEngine velocity = new VelocityEngine();
    
                ExtendedProperties props = new ExtendedProperties();
    
                //定义资源加载器
                props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "EasyNet.Mvc.AssemblyResourceLoader;EasyNet.Mvc");
    
                //初始化
                velocity.Init(props);
    

      

  • 相关阅读:
    使用过滤器对权限进行过滤,就是对访问的url地址进行判断
    百度上传文件到写入数据库之六
    百度上传文件到写入数据库之五
    百度上传文件到写入数据库之四
    百度上传文件到写入数据库之三
    百度上传文件到写入数据库之二
    百度上传文件到写入数据库之一
    FileUpLoad
    文件上传后台解说
    "/FileUpLoad"文件的说明
  • 原文地址:https://www.cnblogs.com/haiyabtx/p/2560824.html
Copyright © 2011-2022 走看看