• 【Java Web开发学习】Spring构造器和属性注入


    测试类

    public class Construct {
        private String address;
        private long phone;
        public Construct(String name, int age) {
            System.out.println("> " + name + ", " + age);
        }
        public String getAddress() {
            return address;
        }
        public void setAddress(String address) {
            System.out.println("> " + address);
            this.address = address;
        }
        public long getPhone() {
            return phone;
        }
        public void setPhone(long phone) {
            System.out.println("> " + phone);
            this.phone = phone;
        }
    }
        <!-- 使用name -->
        <bean id="construct_c1" class="cn.ycx.bean.Construct">
            <constructor-arg name="age" value="1" type="int"></constructor-arg>
            <!-- type可以省略 -->
            <constructor-arg name="name" value="Tom_1"></constructor-arg>
            <!-- 属性配置 -->
            <property name="address" value="xi'an"></property>
            <property name="phone" value="18000"></property>
        </bean>
        <!-- 使用index -->
        <bean id="construct_c2" class="cn.ycx.bean.Construct">
            <constructor-arg index="1" value="2" type="int"></constructor-arg>
            <!-- type可以省略 -->
            <constructor-arg index="0" value="Tom_2"></constructor-arg>
        </bean>
        <!-- 省略name和index,值顺序必须和方法定义保持一致 -->
        <bean id="construct_c3" class="cn.ycx.bean.Construct">
            <constructor-arg value="Tom_3" type="String"></constructor-arg>
            <constructor-arg value="3" type="int"></constructor-arg>
        </bean>
        <!-- c命名空间name -->
        <bean id="construct_c4" class="cn.ycx.bean.Construct" c:name="Tom_4" c:age="4" p:address="beijing" p:phone="136000"></bean>
        <!-- c命名空间index -->
        <bean id="construct_c5" class="cn.ycx.bean.Construct" c:_0="Tom_5" c:_1="5"></bean>
  • 相关阅读:
    python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
    ACM_高次同余方程
    既然选择了、再怎么艰难也要走下去
    ACM_扩展欧几里德算法
    Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
    Codeforces Round #328 (Div. 2)_A. PawnChess
    HDU_5523Game
    POJ_2769同余问题
    poj1258prim算法
    最小生成树—prim算法
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/9872128.html
Copyright © 2020-2023  润新知