初試BeanShell和Apache Commons - Jelly
用Google百度了下,發(fā)現(xiàn)使用 BeanShell最為方便, Apache Commons - Jelly 次之(但最接近原有設計)。下面是做的測試例子。
輸出結果:
|
TestMapping.java
|
test.bsh
|
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<jelly trim="false" xmlns="jelly:core">
<forEach items="${srcList}" var="srcBean">
<new var="destBean" className="java.util.LinkedHashMap" />
<!-- 項目⓪ -->
<set target="${destBean}" property="dep" value="ssod" />
<!-- 項目① -->
<set target="${destBean}" property="nickName" value="${srcBean.name}" />
<!-- 項目② -->
<set target="${destBean}" property="age" value="${srcBean['age']}" />
<!-- 項目③ -->
<choose>
<invokeStatic var="intAge" className="java.lang.Integer"
method="valueOf">
<arg type="java.lang.String" value="${srcBean.age}" />
</invokeStatic>
<when test="${intAge le 18}">
<set target="${destBean}" property="group" value="nonage" />
</when>
<otherwise>
<set target="${destBean}" property="group" value="adult" />
</otherwise>
</choose>
<!-- 項目④ -->
<invokeStatic var="idx" className="java.lang.Long" method="valueOf">
<arg type="long" value="${srcBean['mail'].indexOf('@')+1}" />
<!-- NOTICE : "${1}' class is Integer, but '${1+1}' is Long -->
</invokeStatic>
<set target="${destBean}" property="mailServer"
value="${srcBean['mail'].substring(idx.intValue(), srcBean['mail'].indexOf('.'))}" />
<expr value="${destList.add(destBean)}