当前位置: 首页 > news >正文

临海企业网站建设公司郑州市中标公示网

临海企业网站建设公司,郑州市中标公示网,分销系统平台有哪些,办公室装修设计理念简短范文之前学习basic的时候有个疑问就是不知道如何实现bean中引用其他的bean的属性#xff0c;当时是用ref来实现对其他bean的引用#xff0c;但是ref必需引用的是一个常量。所以这种方式来实现对其他bean中的属性的引用是不合理的。 当我看到Spring Expression Language时发现原来…之前学习basic的时候有个疑问就是不知道如何实现bean中引用其他的bean的属性当时是用ref来实现对其他bean的引用但是ref必需引用的是一个常量。所以这种方式来实现对其他bean中的属性的引用是不合理的。 当我看到Spring Expression Language时发现原来我想实现的ref的效果就是使用Spring EL这种表达式就可以完成了。   而Spring EL有两种配置形式一种是Spring EL 写在xml中和zai xml定义bean一样通过在定义bean的xml标签内使用#{otherBean.property} 或#{otherBean}的形式来完成。另一种是基于注解的方式。一下稍作说明 第一种和第二种都是通过xml来加载spring context的但是xml里的内容不一样 第一种直接在xml中定义spring 的上下文并在bean中的属性字段直接使用SpringEL来引用其他bean或其他bean的属性 第二种: 在xml中定义Component的scan-package的包名这样spring会在这个包中扫描并配置对应的bean然后我们在对应的类中加上注解就可以了.   第一种 ?xml version1.0 encodingUTF-8?beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd bean iditemBean classcom.ric.demo.Item property namename valueitemA/ property nameqty value10/ /bean bean idcustomerBean classcom.ric.demo.Customer property nameitem value#{itemBean} /// 直接在这里使用Spring EL设置值 property nameitemName value#{itemBean.name}/// 直接在这里使用Spring EL设置值 /bean/beans 第二种 定义xml: ?xml version1.0 encodingUTF-8?beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:contexthttp://www.springframework.org/schema/context xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd context:component-scan base-packagecom.ric.demo //beans配置对应的bean Component(customerBean)public class Customer { private Item item; private String itemName; Override public String toString() { return Customer{ item item , itemName itemName \ }; } public Item getItem() { return item; } // 使用Spring EL 来取到对应的value Value(#{itemBean}) public void setItem(Item item) { this.item item; } public String getItemName() { return itemName; }// 使用Spring EL 来取到对应的value Value(#{itemBean.name}) public void setItemName(String itemName) { this.itemName itemName; }}  需要注意的是如果这里的 Spring EL里面引用的是其他的对象有一下这种效果   ApplicationContext context new ClassPathXmlApplicationContext(BeansAutoScan.xml);Item item (Item)context.getBean(itemBean);System.out.println(item);Customer customer (Customer)context.getBean(customerBean);System.out.println(customer);item.setName(geek);System.out.println(item);System.out.println(customer); Item{nameitem, qty10}Customer{itemItem{nameitem, qty10}, itemNameitem}Item{namegeek, qty10}Customer{itemItem{namegeek, qty10}, itemNameitem} Process finished with exit code 0 也就是说如果引用的是item bean 我们的customer的itemBean属性的确是对item这个bean的一个引用。 但是Customer的itemName这个属性的值没有变因为bean扫描的时候也是为上下文中的bean做一个初始化的工作初始化完后item虽然对name做了一个更新的操作但是customer的itemName的指针不会因为item的name做了变化而同步而是依旧指向item原先name值的那个指针                                   转载于:https://www.cnblogs.com/codetime/p/6293489.html
http://www.huolong8.cn/news/94534/

相关文章:

  • 藁城网站建设哪家好网站建设与管理视频
  • 做公司网站的时间开发免费app
  • 平凉市建设局门户网站东莞wordpress
  • 有没有外国人做发明的网站专做品牌网站
  • 做网站运营有前途游戏试玩平台代理
  • 饰品网站建设规划书自学seo能找到工作吗
  • 织梦做网站的详情如何编写网站建设
  • 网站数据库查询怎么做广告公关公司
  • 哪个网站做国内销海外的wordpress hao123
  • 做互联网需要网站吗自助建站系统平台
  • 做商业网站需要注册公司吗甘肃网站备案审核
  • 怎么做系部网站首页美食网站建设服务策划书
  • 网站开发员属于手机端网站做app
  • 移动路由器做网站服务器关于网站制作的指标
  • 网站邮件发送功能怎么做dedecms 手机网站
  • 免费建立网站平台华为商城官网手机版
  • 株洲网站建设 株洲网站制作wordpress无法打开
  • 网站建设微商城制作模板网站
  • 茂名网站建设公司搬瓦工安装wordpress
  • 慈溪哪点有学做网站的凯里有哪些网站开发公司
  • 网站开发 只要网页游戏网络游戏
  • 网站建设服务预算南京林业大学实验与建设网站
  • 章贡区综合网站建设商家网站后台不显示文章内容
  • 广州做网站专业公司江苏弘盛建设工程集团有限公司网站
  • 阿里云买啦域名怎么建设网站软文撰写
  • 青岛大学春季高考有网站建设吗手机报价网站大全
  • 在外国做玄幻小说网站百度关键词排名
  • 太原网站建设平台网站开发后台注意事项
  • 随州网站建设学校织梦网站怎么做投票
  • 网站制作课程多少钱电脑如何重新安装wordpress