zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    通用二进制格式安装、编译安装过程(以mysql为例)
    linux:网络
    深圳:软通-运维
    深圳:软通-python
    linux:用户管理
    linux:vim
    深圳:卡莱特-售前/售后服务
    linux:基本指令
    linux:安装
    电脑:磁盘扩容
  • 原文地址:https://www.cnblogs.com/macula7/p/1960446.html
Copyright © 2011-2022 走看看