zoukankan      html  css  js  c++  java
  • Spring的基本操作

    第一步:创建资源包    source  在资源包下面创建   applicationContext.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="zhanshenarmet" class="cn.yct.entity.Equip">       对应实体类的包名+类名
    <property name="name" value="战神头盔"> </property>
    <property name="type" value="头盔"></property>
    <property name="speedPlus" value="2"></property>              对应实体类中的属性名
    <property name="attackPlus" value="4"></property>
    <property name="defencePlus" value="6"></property>
    </bean>

    <bean id="posizhuifengboot" class="cn.yct.entity.Equip">        对应实体类的包名+类名
    <property name="name" value="珀斯追风靴"> </property>
    <property name="type" value="靴子"></property>
    <property name="speedPlus" value="8"></property>               对应实体类中的属性名
    <property name="attackPlus" value="2"></property>
    <property name="defencePlus" value="3"></property>
    </bean>


    <!-- 张三 -->      ref  引用bean的id名称
    <bean id="zhangsan" class="cn.yct.entity.Player" >
    <property name="armet" ref="zhanshenarmet"> </property>
    <property name="loricae" ref="lianhuansuoloricae"></property>
    </bean>

    </beans>

    第二步:创建测试类   Test     Player  Equip   实体类

    ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");         对应XML的名称

    Player player=(Player)context.getBean("zhangsan");

    Equip equip1=(Equip)context.getBean("zhanshenarmet");     
    Equip equip2=(Equip)context.getBean("posizhuifengboot");

  • 相关阅读:
    Centos7安装Docker
    [LeetCode] 651. 四键键盘 ☆☆☆(动态规划)
    一行代码就能解决的算法题
    博弈问题--石头游戏(动态规划)
    [LeetCode] 322. 零钱兑换 ☆☆☆(动态规划)
    java趣题
    [LeetCode] 516. 最长回文子序列 ☆☆☆(动态规划)
    [LeetCode] 337. 打家劫舍III ☆☆☆(动态规划)
    算法基础--贪心算法
    [LeetCode] 42. 接雨水 ☆☆☆☆☆(按列、动态规划、双指针)
  • 原文地址:https://www.cnblogs.com/y-c-t/p/8505988.html
Copyright © 2011-2022 走看看