Score
0
Watch 9 Star 9 Fork 1

xskaco123 / DynamicRenderJavaMIT

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

#动态渲染(DynamicRender) Build Status on GitHub: https://github.com/xushunke/DynRenderer
on OSC-Git: http://git.oschina.net/xushunke/DynamicRender

可使用多种模板引擎(Velocity,Freemarker),基于[统一]配置[可运行时更改生效]方式,运行时渲染SQL(NOT_ONLY_SQL),无框架依赖,可配合jdbc,jdbcTemplate等使用
use Template Engine(like Velocity),render the SQL(not only sql) dynamically via configure file,no framework dependency,it can be used for jdbc,jdbcTemplate, and etc..

##特性(Feature)

  • 兼容性强,为多种模板引擎,提供统一配置方式;
  • COMPATIBILITY,multiple engines of renderer,one way 2 config;
  • 可读性强,较程序控制的动态SQL,使用'模板引擎+SQL'的方式,编写的SQL可读性更强,换来较好的维护性;
  • READABLE,compare with using java code,using 'template engine + SQL' make the SQL more readable,which also improving maintenance 4 code;
  • 可动态替换,不会出现.class文件替换错误的情况,这代表只要编辑好xml,更新下资源,刷新下页面sql就起效了
    (调试神器,(no more hot-swap failed),这需要在配置文件显式申明cmd-col[doDebug=true],timeCost将有所增加);
  • SWAP_DYNAMICALLY,no more hot-swap failed,it means while u modified config file,upload the resource,refresh the page,the change will appear.(this required declare cmd-col[doDebug=true] in config file,timeCost will increase);
  • 可插拔性强,即便真是因为这个工具出了问题,也不用做框架层次的整改,在相应方法上修改成原来的方法就行了,
    调整小(见net.zdsoft.demo.dao.impl.DemoDaoImpl);
  • PLUGABLE,even some problem do apear due 2 this tool,u have not 2 change the hole architecture,just modify the corresponding method(see net.zdsoft.demo.dao.impl.DemoDaoImpl);
  • 轻量级,仅仅用来生成SQL语句,不含jdbc执行;
  • LIGHT_WEIGHT,only do the work of render;
  • 模板语言自定义性强,可定义模板语言的常用函数,在引擎时渲染时使用,提高重用性(见resources/lib.vm);
  • CUSTOMIZE_THE_ENGINE,customize the macro of the template engine is available(see resources/lib.vm)

##用例(Usage)


<?xml version="1.0" encoding="UTF-8"?>
<cmd-collection xmlns="http://ACoinWork.com"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://ACoinWork.com command.xsd"
                engine="VELOCITY" >
    <!--cmd-collection[engine]表示使用何种渲染引擎,现在支持velocity-->
    <!-- cmd[id],为cmd做标识,在代码中将得到引用-->
    <cmd id="cmd1">
        <!--代表介绍,描述,供人阅读-->
        <description>
            hello
        </description>
        <!--预渲染字段,渲染引擎由cmd-collection[engine]决定-->
        <!--此处用了sql,但不代表只能用sql.邮件模板,html,post参数模板,json模板...whatever u want--> 
        <!--此处出现#@bracket为我自己定义的函数,具体见resources/lib.vm(函数库路径由ACoinWork.properties[libPath]决定)--> 
        <!--pre-render在运行时改变后更新能即刻响应(刷新页面,而非重启容器)(需显式申明ACoinWork.properties[doDebug=true])--> 
        <pre-render><![CDATA[
            select * from A where A.age in #@bracket($list)$ele.age#end;
        ]]>
        </pre-render>
    </cmd>
</cmd-collection>

/**
 * 演示dao
 *
 * @author xusk
 * @Date: 15/12/31 下午3:58
 */
public class DemoDaoImpl extends MockDao implements DemoDao {
    private static final Organizer<VelocityContext> organizer =
            new Organizer<VelocityContext>("/command.xml", "http://ACoinWork.com");

    /**
     * 演示一个dao的方法如何使用
     *
     * @param list
     * @return
     */
    @Override
    public List<Object> getListByIds(List<DemoPerson> list) {
        //实例化渲染上下文
        VelocityContext ctx = new VelocityContext();
        ctx.put("list", list);
        //organizer.getResById("cmd1", ctx)
        //通过cmd[id]与渲染上下文获得渲染后的资源
        final List<Object> result = query(organizer.getResById("cmd1", ctx));
        
        return result;
    }

}

that`s all.Simple and Useful.

##类图(DiagramExplanation)
DiagramExplain

Comments ( 0 )

Sign in for post a comment

About

通过配置文件[可运行时更改生效]的方式,使用模板引擎(Velocity),运行时渲染SQL(NOT_ONLY_SQL),无框架依赖,可配合jdbc,jdbcTemplate等使用 spread retract
MIT
Cancel

Releases

No release

Gitee Metrics

Contributors

All

Activities

load more
can not load any more