Velocity学习笔记
代码样例
Velocity宏样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#macro( finHead $head ) #set( $params = $springCtx.getBean('appConfig').params ) <HEAD> <VER>${params.version}</VER> <SRC>${params.srcNode}</SRC> <DES>${params.destNode}</DES> <APP>${params.appName}</APP> <MsgNo>$head.msgNo</MsgNo> <MsgNoOld>$!{head.msgNoOld}</MsgNoOld> <MsgID>$head.msgId</MsgID> <MsgRef>$head.msgRef</MsgRef> <WorkDate>$head.workDate</WorkDate> <Reserve></Reserve> </HEAD> #end |
一个比较复杂的实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> #foreach($em in $ems) ##循环处理所有实体映射定义 <class entity-name="$em.name" #if($em.node) node="$em.node" #end table="$em.table"> #set($pms = $em.allPropertyMappings) #foreach($pm in $pms) #if($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.IdPropertyMapping")) ##标识符属性 #set($idElName = "id") #if($pm.composite) #set($idElName = "composite-id") #end <$idElName name="$pm.name" #if($pm.node) node="$pm.node" #end #if(not $pm.composite) type="$pm.uniqueKeyMapping.type" #end> #set($kms = $pm.keyMappings) #foreach($km in $kms) #if($pm.composite) <key-property name="$km.name" #if($km.node) node="$km.node" #end type="$km.type" column="$km.column" /> #else <column name="$km.column"/> #end #end <generator class="assigned" /> </$idElName> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.SimplePropertyMapping")) ##简单属性 <property name="$pm.name" #if($pm.node) node="$pm.node" #end type="$pm.type" column="$pm.column" /> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.O2MPropertyMapping")) ##一对多引用 <set name="$pm.name" #if($pm.node) node="$pm.node" #end cascade="all" fetch="join" lazy="false"> <key> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </key> <one-to-many entity-name="$pm.refEntityMapping.name"/> </set> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.M2OPropertyMapping")) ##多对一引用 <many-to-one name="$pm.name" #if($pm.node) node="$pm.node" #end entity-name="$pm.refEntityMapping.name" cascade="all" fetch="join" lazy="false"> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </many-to-one> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.M2MPropertyMapping")) ##多对多引用(join-table based) <set name="$pm.name" #if($pm.node) node="$pm.node" #end table="$pm.joinTable" cascade="all" fetch="join" lazy="false"> <key> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </key> <many-to-many entity-name="$pm.refEntityMapping.name"> #set($okms = $pm.oppoKeyMappings) #foreach($okm in $okms) <column name="$okm.column"/> #end </many-to-many> </set> #end #end </class> #end </hibernate-mapping> |
17 years ago
0