castor 集合对象的多态映射

今天在使用castor需要用多态映射(我不知是不是这个叫法:)),网上找了很多资料,然后终于找到一篇差不多的资料,下面是一个例子

public class PageControl {
    /**
     * 控件类型
     */
    protected String type;
    /**
     * 控件标签
     */
    protected String label;
    /**
     * 控件名
     */
    protected String name;
    /**
     * 控件值
     */
    protected String value;
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getLabel() {
        return label;
    }
    public void setLabel(String label) {
        this.label = label;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
   
}

 

public class Radio extends PageControl {
    public Radio(){
        this.type="radio";
    }
    private String viewLabel;
    public String getViewLabel() {
        return viewLabel;
    }
    public void setViewLabel(String viewLabel) {
        this.viewLabel = viewLabel;
    }
   
}

 

public class Text extends PageControl {
    public Text(){
        this.type="text";
    }
}

 

xml的配置如下:

<field name="fieldControlTypeMap" type="com.ssgm.jaoe.generator.control.PageControl" collection="arraylist">
  <bind-xml auto-naming="deriveByClass" node="element" location="fieldControlTypeMap"></bind-xml>
 </field>
<class name="com.ssgm.jaoe.generator.control.PageControl">
 <field name="type" type="string" >
  <bind-xml name="type" node="attribute"/>
    </field>
    <field name="label" type="string" >
  <bind-xml name="label" node="attribute"/>
    </field>
    <field name="name" type="string" >
  <bind-xml name="name" node="attribute"/>
    </field>
    <field name="value" type="string" >
  <bind-xml name="value" node="attribute"/>
    </field>
</class>
<class name="com.ssgm.jaoe.generator.control.Text" extends="com.ssgm.jaoe.generator.control.PageControl">
 <map-to xml="text"/>
</class>
<class name="com.ssgm.jaoe.generator.control.Radio" extends="com.ssgm.jaoe.generator.control.PageControl">
 <map-to xml="radio"/>
</class>
然后只要在配置文件中配置如下就可以实现了:
<fieldControlTypeMap>
            <radio name="sex" operate=“CRUD”/>
            <select name="companyId" operate=“CRUD”/>
</fieldControlTypeMap>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值