zoukankan      html  css  js  c++  java
  • spring

    spring:一个开源的框架。
    
    1 创建applicationContext.xml 配置文件
    
    1)配置bean
    
    <bean id="helloworld" class = "com.ljs.spring.beans.HelloWorld" scope="prototype">
        <property name="name" value="ljs"></property>
    </bean>
    
    id: bean的唯一标识
    class: 指定全类名
    property: 通过set方法给指定的属性赋值
    
    2. 创建ioc 容器,并容器中获取bean
        ApplicationContext context = 
                new ClassPathXmlApplicationContext("aplicationContext.xml");
        HelloWorld h1 = (HelloWorld) context.getBean("helloworld");
        
    -------------------
    依赖注入:
    1  set 方法注入
    <bean id="car" class="com.ljs.spring.beans.Car" >
        <property name="name" value="baoma"></property>
        <property name="price" value="10000"></property>
    </bean>
    
    2  构造器注入:提供对应的构造器。
    <bean id="car01" class="com.ljs.spring.beans.Car">
        <constructor-arg value="baoma"></constructor-arg>
        <constructor-arg value="123"></constructor-arg>
    </bean>
    
    3  注入含有对象
    <bean id="person" class="com.ljs.spring.beans.Person">
        <property name="name" value="sb"></property>
        <property name="car" ref="car"></property>
    </bean>
    
    4 注入对象中含有对象列表
    <bean id="personlist" class="com.ljs.spring.beans.PersonList">
        <property name="name" value="shbb"></property>
        <property name="cars" >
            <list>
                <ref bean="car" />
                <ref bean="car01" />
            </list>
        </property>
    </bean>
    
    5. 注入对象中含有字典map
    <bean id="personmap" class="com.ljs.spring.beans.PersonMap">
        <property name="name" value="xiaoting"></property>
        <property name="map" >
            <map>
                <entry key="first" value-ref="car"/>
                <entry key="second" value-ref="car01" /> 
            </map>
        </property>
    </bean>
  • 相关阅读:
    金融数据获取的api接口
    股票实时数据接口
    【C#】通过webbrowser控件自动注册QQ号讲解
    【C#】通过webbrowser控件获取验证码
    光圈,快门, 曝光,焦距, ISO,景深。
    装修记录
    cocos2dx在win10系统上的VS2017运行时报错:丢失MSVCR110.dll
    论打击的本质(2)-视觉理论及应用篇
    论打击感的本质(1)——力的理论及应用
    android屏幕适配详解
  • 原文地址:https://www.cnblogs.com/lijins/p/10235401.html
Copyright © 2011-2022 走看看