• 第二节 模拟实际开发流程


     正在构建,扫一扫,敬请期待

    和玩得来的人在一起玩才叫玩!

    和玩不来的人在一起玩,那种感觉就像加班啊!

    关注胖个人微信公众账号,希望对各位学生有所帮助!

     

    --胖先生

       


    回顾
    :

    1.SpringIoC控制反转[DI->依赖注入]和AOP的容器框架

    2.核心IoC把维护Bean的生命周期交给了Spring的容器框架

    3.注入:

    1. Setter注入方式[1.名称,两个连续小写,2,特殊字符[2] 3.对应的不是属性名,是对应的set方法后的首字母小写的名称]
    2. 构造函数的注入方式[推荐使用混合模式-->index type]
    3. 静态工厂

    4. 关于List Set Array Map 属性文件注入

    5.生命周期的访问scope

    6.关于赋值 3中方式

    1. 标准方式<property name=""><value>|<ref bean>
    2. 简写方式<property name value/>
    3. 使用p标签来完成[推荐]

    注入自定义的对象,使用setter方法会

    <!-- 只是实例化Person -->

    <bean id="person" class="com.shxt.model.Person">

    <property name="name" value="悟空" />

    <property name="homeAddress">

    <!-- 通过id看是否能获取Address对象 -->

    <bean id="address" class="com.shxt.model.Address">

    <property name="address">

    <value>花果山</value>

    </property>

    </bean>

    </property>

       

    </bean>

    public class SpringTest {

    private ApplicationContext ac = null;

    @Before //下面说有的测试方法执行之前,先执行@Before

    public void init(){

    ac = new ClassPathXmlApplicationContext("beans.xml");

    }

    @Test

    public void 获取用户信息(){

    Person person = ac.getBean("person", Person.class);

    System.out.println(person.getName());

    System.out.println(person.getHomeAddress().getAddress());

    //问题: 通过ID获取单独的地址对象,是否能成功? 不成功,因为作用访问是隶属于person

    Address address = ac.getBean("address", Address.class);

    }

       

    }

       

    推荐的写法为<ref bean="外部定义的id">

    <bean id="address" class="com.shxt.model.Address">

    <property name="address">

    <value>花果山</value>

    </property>

    </bean>

       

    <!-- 只是实例化Person -->

    <bean id="person" class="com.shxt.model.Person">

    <property name="name" value="悟空" />

    <property name="homeAddress">

    <!-- 1. 通过id看是否能获取Address对象 -->

    <ref bean="address"/>

    </property>

    <property name="workAddresses">

    <list>

    <ref bean="address"/>

    <!-- 这里定义的ID没有任何意义,外部无法获取到,因为它之作用于Person下 -->

    <bean id="address" class="com.shxt.model.Address">

    <property name="address">

    <value>宫廷</value>

    </property>

    </bean>

    </list>

    </property> 

    </bean>

    address 标注的为引用方式,推荐方式

    @Test

    public void 获取用户信息(){

    Person person = ac.getBean("person", Person.class);

    System.out.println(person.getName());

    //System.out.println(person.getHomeAddress().getAddress());

    //问题: 通过ID获取单独的地址对象,是否能成功?

    Address address = ac.getBean("address", Address.class);

    System.out.println(address.getAddress());

    //遍历工作地址

    for (Address a : person.getWorkAddresses()) {

    System.out.println(a.getAddress());

    }

    }

       

    模拟开发流程之 XML方式

    正常的开发流程为: 首先构建领域模型,其次创建数据访问层,再创建业务逻辑层,最后创建控制层[不考虑视图层]

    而调用关系,正好相反

       

       

       

    实际开发说明: 一般情况下XML版本大多用于大型项目,好处在于通过XML文件能知道相互的调用关系

       

       

    标注注解方式,推荐写法为:

       

       

       

       

       

       

       

       

       

       

       

       

       

  • 相关阅读:
    从IRP说起(转)
    IoSkipCurrentIrpStackLocation .(转)
    IO_REMOVE_LOCK使用方法小结(转载加改正)
    TCP释放连接时为什么time_wait状态必须等待2MSL时间
    网络编程之select
    Ubuntu18.04 安装Chrome浏览器
    Ubuntu修改系统时间
    Linux常用命令总结
    struct ifconf和struct ifreq,获取网线插入状态
    一个简单的客户单与服务端程序
  • 原文地址:https://www.cnblogs.com/pangxiansheng/p/5422907.html
Copyright © 2020-2023  润新知