美文网首页
velocity整理

velocity整理

作者: 瑜骐 | 来源:发表于2018-10-26 22:37 被阅读0次

调试相关

不管使用什么语言,引擎,工具去开发,对于开发人员来说最主要还是要有对应的调试方法,而对于像velocity这样模版引擎的编写,没有很直接的调试方法,但是我们可以曲线救国,通过如下方式进行调试:

package com.yjk.framework.dalgen;

import lombok.extern.slf4j.Slf4j;

/**
 * @author yujiakui
 * @version 1.0
 * Email: jkyu@haiyi-info.com
 * date: 2018/10/19 13:26
 * description:
 **/
@Slf4j
public class TestLogOutput {

    public boolean print(Object object){
        log.info("----print---obj={}",object);
        System.out.println("---------XXX------");
        return true;
    }
}

将这个测试类注入到模版引擎的上下文中,然后在vm模版文件中使用如下方式进行调用:

package ${package.Mapper};

import ${package.Entity}.${entity};
import ${superMapperClassPackage};
import org.apache.ibatis.annotations.Param;


/**
 * <p>
 * $!{table.comment} Mapper 接口
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
#if(${kotlin})
interface ${table.mapperName} :${superMapperClass}<${entity}>
#else
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
#* 这里的log对应的就是上面的TestLogOutput对象,通过这种方式进行调试*#
#set($log=${cfg.map.log})
    #foreach($operation in ${tableOpInfo.sqlOpInfos})
       #* #if($log.print($foreach.count))
        #end*#
        #parse("templates/operation/op-${operation.templateSuffix}.vm");
    #end
    #*#foreach($operation in ${cfg.map.sqlCfg.tableConfigs.get(${table.name}).operations})
    #if(!$operation.resultMap && !$operation.resultClass)
    ${entity}
    #elseif($operation.resultMap)
    $operation.resultMap
    #elseif($operation.resultClass)
    $operation.resultClass
    #end
        ${operation.name}(
        #foreach($param in $operation.sqlParser.params)
            #if($velocityCount > 1)
                    ,
            #end
                String $param
        #end
            );
#end*#
}
#end

velocity使用场景

velocity可以用在很多场景,特别是各种报表,通过velocity可以动态加载和修改报表的输出样式等;目前用velocity是在mybatis plus中根据sql生成对应的dao层代码和service层代码,具体代码可以参见:https://github.com/lwjaiyjk/dalgenForMybatisPlus

相关文章

  • velocity整理

    调试相关 不管使用什么语言,引擎,工具去开发,对于开发人员来说最主要还是要有对应的调试方法,而对于像velocit...

  • velocity基本使用

    1. Velocity 开发 apache Velocity开发指导传送门 1.1 Velocity使用流程 初始...

  • 模板引擎velocity

    本文基于 Velocity 1.7 版本撰写。 概述 什么是Velocity? Velocity是一个基于java...

  • Spring MVC 整合 Velocity

    根据网上资料整理 发布于:2016-10-31 Apache Velocity是一款基于Java的模板引擎,允许使...

  • RNA velocity处理流程

    关于RNA velocity RNA velocity介绍[https://www.jianshu.com/p/7...

  • 破解 Velocity

    1. Velocity (Dash for Windows) Velocity 是一款API查询工具,是Dash在...

  • Eclipse使用

    eclipse velocity插件

  • Velocity

    Velocity入门链接 https://blog.csdn.net/qq_25237663/article/de...

  • velocity

    18.8.28 if($some > 1) 有点时候不生效,不论大于还是小于都是false。原因:跟传入时的类型...

  • Velocity

    类型操作 String 转换为 Integer Note: 类型转型前必须得先确定要转换的对象是存在的,否则会导致...

网友评论

      本文标题:velocity整理

      本文链接:https://www.haomeiwen.com/subject/hxqrtqtx.html