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");

 

转载于:https://www.cnblogs.com/y-c-t/p/8505988.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值