2017-08-24 34 views
0
package com.protect.shapes; 

public class Triangle { 
    String Type = null; 
    String type = null; 

    public String getType() { 
     return Type; 
    } 

    public void setType(String Type) { 
     this.Type = Type; 
    } 

    public String gettype() { 
     return type; 
    } 

    public void settype(String type) { 
     this.type = type; 
    } 

    public void draw() { 
     System.out.println("Drawing " + type + " Triangle. " + Type); 
    } 
} 

Configuration file. 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 
<!-- Project beans go here --> 
<bean id="triangle" class="com.protect.shapes.Triangle"> 
    <property name="Type" value="Equilateral"> 
    </property> 
</bean> 

我試圖檢查Spring是如何處理區分大小寫的屬性名稱,但不能弄明白:同時爲typeType領域我把我得到的結果相同如何解析Spring區分大小寫的屬性名稱

"Drawing Equilateral Triangle. null". 

您能否介紹一下爲什麼以及如何實例化Type字段。

回答

1

春找不到一個二傳手您Type屬性:

  • setType不會做,因爲根據該指type財產
  • settype是無效java beans specification因爲它沒有被識別爲根據相同規格的財產製定者。

如果你想要一個大寫字母名稱屬性,它應該以(至少)兩個大寫字母開始,例如,該規範的

public void setPType(...) { 
    ... 
} 

<property name="PType" value="..."/> 

檢查部分8.8。

相關問題