spring中为属性定义集合

为类添加一个

private Map<Object,Object>suffix2;属性

方法修改如下:

public synchronized String getSequence(){
   StringBuilder sb=new StringBuilder();
   sb.append(prefix);
   sb.append(initial+counter++);
   sb.append(suffix);
   for (Map.Entry<Object, Object> entry : suffix2.entrySet()) {
    sb.append("_");
    sb.append(entry.getKey());
    sb.append("@");
    sb.append(entry.getValue());
   }
   return sb.toString();
}
public void setSuffix2(Map<Object, Object> suffix2) {
   this.suffix2 = suffix2;
}

配置文件配置如:

<bean id="sequenceGenerator" class="com.wfb.beans.SequenceGenerator" dependency-check="default">
   <property name="prefix" value="30"></property>
   <property name="suffix" value="A"></property>
   <property name="initial" value="1000"></property>
   <property name="cb" ref="childBean"></property>
   <property name="suffix2">
    <map>
     <entry>
      <key>
      <value>type</value>
      </key>
      <value>A</value>
     </entry>
     <entry>
      <key>
       <value>url</value>
      </key>
      <bean class="java.net.URL">
       <constructor-arg value="http"></constructor-arg>
       <constructor-arg value="www.appress.com"></constructor-arg>
       <constructor-arg value="/"></constructor-arg>
      </bean>
     </entry>
    </map>
   </property>
   <constructor-arg type="java.lang.String" index="0" value="10000"></constructor-arg>
   <constructor-arg index="1" value="A"></constructor-arg>
   <constructor-arg index="2" value="1000"></constructor-arg>
</bean>

这样test运行结果如下:

301000A_type@A_url@http://www.appress.com/
301001A_type@A_url@http://www.appress.com/

posted @ 2010-05-08 00:30  macula7  阅读(304)  评论(0编辑  收藏  举报