2

我的 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

我想要输出(person Bean):-

bellary
4

1 回答 1

0

What you have is perfectly fine assuming your getters and setters are named accordingly.

Address class

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 class

public class person {
    private String cityname;

    public String getCityname() {
        return cityname;
    }

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

Remember that Spring beans follow the naming conventions of Java Beans. You should also follow Java naming conventions. Class names should start with an uppercase letter and use CamelCase. H_NO not very descriptive. Use homeNumber or something similar.

于 2013-10-08T12:34:37.587 回答