如何将Address的属性值从Address bean设置为person bean的cityname属性

时间:2013-10-08 11:44:15

标签: spring

我的XML:

<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
                               http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean  id="add" class="com.basu.Address">
    <property name="H_NO" value="7"/>
    <property name="city" value="bellary"/>
    <property name="state"  value="karnataka"/>
    </bean>

    <bean id="per" class="com.basu.person" >
    <property name="cityname" value="#{add.city}"/> 
    </bean>

</beans>

我想要输出(地址Bean): -

7
bellary
karnataka

我想要输出(人豆): -

bellary

1 个答案:

答案 0 :(得分:0)

如果您的吸气剂和制定者的名字相应命名,那么您所拥有的就完全没有了。

Address上课

public class Address {
    private String H_NO;
    private String city;
    private String state;
    public String getH_NO() {
        return H_NO;
    }
    public void setH_NO(String h_NO) {
        H_NO = h_NO;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
}

person上课

public class person {
    private String cityname;

    public String getCityname() {
        return cityname;
    }

    public void setCityname(String cityname) {
        this.cityname = cityname;
    }
}

请记住,Spring bean遵循Java Bean的命名约定。您还应遵循Java命名约定。类名应以大写字母开头,并使用CamelCaseH_NO不是很具描述性。使用homeNumber或类似的东西。