使用定义的xml模板
定义负责的输出模式可以使用xml模板,模板的名字同bean名称相同,后缀为.betwixt
例如
packagebetwixt;


/***//**
*
*/


/***//**
*@authorhuyunan
*
*
*2007aspire
*/
publicclassDoc

...{

privateStringversion;
privateStringname;

privateStringurl;

publicDoc()

...{

}


/***//**
*@returnthename
*/
publicStringgetDocName()

...{
returnthis.name;
}


/***//**
*@paramname
*thenametoset
*/
publicvoidsetName(Stringname)

...{
this.name=name;
}


/***//**
*@returntheurl
*/
publicStringgetUrl()

...{
returnthis.url;
}


/***//**
*@paramurl
*theurltoset
*/
publicvoidsetUrl(Stringurl)

...{
this.url=url;
}


/***//**
*@returntheversion
*/
publicStringgetVersion()

...{
returnthis.version;
}


/***//**
*@paramversion
*theversiontoset
*/
publicvoidsetVersion(Stringversion)

...{
this.version=version;
}

}
默认输出为
<doc>
<version>1.0.0</version>
<url>doc_url</url>
<docName>doc_name</docName>
</doc>
使用xml Doc.betwixt
<?xmlversion="1.0"encoding="UTF-8"?>
<infoprimitiveTypes="element">
<elementname="docResource">
<elementname="contentUrl"property="url"/>
<addDefaults/>
</element>
</info>
则输出结果为
<doc>
<version>1.0.0</version>
<contentUrl>doc_url</contentUrl>
<docName>doc_name</docName>
</doc>
可以将元素指定为属性来处理
<?xmlversion="1.0"encoding="UTF-8"?>
<infoprimitiveTypes="element">
<elementname="docResource">
<attributename="version"property="version"/>
<elementname="contentUrl"property="url"/>
<addDefaults/>
</element>
</info>
则输出结果为
<docversion="1.0.0">
<contentUrl>doc_url</contentUrl>
<docName>doc_name</docName>
</doc>
定义负责的输出模式可以使用xml模板,模板的名字同bean名称相同,后缀为.betwixt
例如
packagebetwixt;

/***//**
*
*/

/***//**
*@authorhuyunan
*
*
*2007aspire
*/
publicclassDoc
...{
privateStringversion;
privateStringname;
privateStringurl;
publicDoc()
...{
}

/***//**
*@returnthename
*/
publicStringgetDocName()
...{
returnthis.name;
}

/***//**
*@paramname
*thenametoset
*/
publicvoidsetName(Stringname)
...{
this.name=name;
}

/***//**
*@returntheurl
*/
publicStringgetUrl()
...{
returnthis.url;
}

/***//**
*@paramurl
*theurltoset
*/
publicvoidsetUrl(Stringurl)
...{
this.url=url;
}

/***//**
*@returntheversion
*/
publicStringgetVersion()
...{
returnthis.version;
}

/***//**
*@paramversion
*theversiontoset
*/
publicvoidsetVersion(Stringversion)
...{
this.version=version;
}
}
默认输出为
<doc>
<version>1.0.0</version>
<url>doc_url</url>
<docName>doc_name</docName>
</doc>
使用xml Doc.betwixt
<?xmlversion="1.0"encoding="UTF-8"?>
<infoprimitiveTypes="element">
<elementname="docResource">
<elementname="contentUrl"property="url"/>
<addDefaults/>
</element>
</info>
则输出结果为
<doc>
<version>1.0.0</version>
<contentUrl>doc_url</contentUrl>
<docName>doc_name</docName>
</doc>
可以将元素指定为属性来处理
<?xmlversion="1.0"encoding="UTF-8"?>
<infoprimitiveTypes="element">
<elementname="docResource">
<attributename="version"property="version"/>
<elementname="contentUrl"property="url"/>
<addDefaults/>
</element>
</info>
则输出结果为
<docversion="1.0.0">
<contentUrl>doc_url</contentUrl>
<docName>doc_name</docName>
</doc>
本文介绍如何使用Betwixt进行XML输出定制,通过定义XML模板改变Java Bean的输出结构,实现元素名称及属性的灵活调整。
137

被折叠的 条评论
为什么被折叠?



