Ⅲ.spring的點點滴滴--賦值

承接上文

對象的賦值(調用方式都同樣再也不闡述)


.net篇(環境爲vs2012+Spring.Core.dll v1.31

public class PropertyDemo{
   public System.Collections.ArrayList PropertyList { get; set; }
   public System.Collections.Specialized.HybridDictionary PropertyDictionary { get; set; }
   public System.Collections.Specialized.NameValueCollection PropertyNameValue { get; set; }
   public Spring.Collections.Set PropertySet { get; set; }
   public System.Collections.Generic.List<string> PropertyStrList { get; set; }
   public System.Collections.Generic.Dictionary<string, string> PropertyStrDictionary { get; set; }
   public string this[int index]  {
      get { return (string)PropertyList[index]; }
      set { PropertyList[index] = value; }
   } 
   public string this[string keyName] {
      get { return (string)PropertyDictionary[keyName]; }
      set { PropertyDictionary.Add(keyName, value); } 
   }
   public DateTime PropertyTime { get; set; }
}
<object name="PropertyDemo" type="SpringBase.PropertyDemo,SpringBase">
    <property name="PropertyList">
      <list>
        <value>a list element followed by a reference</value>
      </list>
    </property>
    <property name="PropertyDictionary">
      <dictionary>
        <entry key="a string => string entry" value="just some string"/>
      </dictionary>
    </property>
    <property name="PropertyNameValue">
      <name-values>
        <add key="HarryPotter" value="The magic property"/>
        <add key="JerrySeinfeld" value="The funny (to Americans) property"/>
      </name-values>
    </property>
    <property name="PropertySet">
      <set>
        <value>just some string</value>
      </set>
    </property>
    <property name="PropertyStrList">
      <list element-type="string">
        <value>a</value>
        <value>b</value>
        <value>c</value>
      </list>
    </property>
    <property name="PropertyStrDictionary">
      <dictionary key-type="string"  value-type="string">
        <entry key="zero">
          <value>jerry</value>
        </entry>
        <entry key="one">
          <value>Month</value>
        </entry>
        <entry key="two">
          <value>Nikola Tesla</value>
        </entry>
        <entry key="three">
          <value>DateTime.Today</value>
        </entry>
      </dictionary>
    </property>
    <property name="[0]" value="Master Shake"/> 
    <property name="['one']" value="uno"/>
    <property name="PropertyTime" expression="DateTime.Today + 7"/>
  </object>

上面的標籤和csharp的類型須要對應或者用基類也能夠, expression是表達式運行的時候會自動換行爲響應的值,key-type設置是泛型屬性key的類型, key-value設置是泛型屬性值的類型,屬性索引老版本可能不是這樣的設置的 html


java篇(環境爲Maven+Jdk1.7+IntelliJ IDEA 12.1.4

package springdemo;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
public class PropertyDemo {
    private ArrayList propertyList;
    public ArrayList getPropertyList() {
        return propertyList;
    }
    public void setPropertyList(ArrayList propertyList) {
        this.propertyList = propertyList;
    }
    private Map propertyDictionary;
    public Map getPropertyDictionary() {
        return propertyDictionary;
    }
    public void setPropertyDictionary(Map propertyDictionary) {
        this.propertyDictionary = propertyDictionary;
    }
    private Set propertySet;
    public Set getPropertySet() {
        return propertySet;
    }
    public void setPropertySet(Set propertySet) {
        this.propertySet = propertySet;
    }
    private Properties  propertyprops;
    public Properties getPropertyprops() {
        return propertyprops;
    }
    public void setPropertyprops(Properties propertyprops) {
        this.propertyprops = propertyprops;
    }
}
<bean id="PropertyDemo" class="springdemo.PropertyDemo">
        <property name="propertyList">
            <list>
                <value>a list element followed by a reference</value>
            </list>
        </property>
        <property name="propertyDictionary">
            <map>
                <entry key="a string => string entry" value="just some string"/>
            </map>
        </property>
        <property name="propertySet">
            <set>
                <value>just some string</value>
            </set>
        </property>
        <property name="propertyprops">
            <props>
                <prop key="db">172.0.0.1</prop>
                <prop key="name">myself</prop>
            </props>
        </property>
 </bean>

不知道java東西少仍是什麼只有這些,由於java是僞泛型也不支持屬性索引器, 由於沒有文檔都是參考c# 探索出javajava


javaCsharp的共同點 spring

其中咱們在標籤裏面還能夠用ref | idref標籤或者屬性來經過id | name引用其餘的對象, 許多標籤的屬性能夠看成一個獨立的標籤,以下 express

<entry key="myKey"> <value>hello</value></entry>

java中必需要有set字段的方法,Csharp能夠省略 c#


相關文章
相關標籤/搜索