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

智慧团建网站注册wordpress国内最流行的主题

智慧团建网站注册,wordpress国内最流行的主题,相亲网站建设策划书范文,免费外贸自建网站SpringEL初始 文章目录 SpringEL初始什么是SpringELSpring BeansSpring EL以XML形式Spring EL以注解形式启用自动组件扫描 执行输出 什么是SpringEL Spring EL与OGNL和JSF EL相似,计算评估或在bean创建时执行。此外,所有的Spring表达式都可以通过XML或注…

SpringEL初始

文章目录

  • SpringEL初始
    • 什么是SpringEL
    • Spring Beans
    • Spring EL以XML形式
    • Spring EL以注解形式
      • 启用自动组件扫描
    • 执行输出

什么是SpringEL

  • Spring EL与OGNL和JSF EL相似,计算评估或在bean创建时执行。此外,所有的Spring表达式都可以通过XML或注解
  • 我们将学习如何使用Spring表达式语言(SpEL),注入字符串,整数,Bean到属性,无论是在XML和注释

Spring Beans

两个简单Bean,后来利用 SpEL 注入值到属性,在 XML 和 注释。

public class Customer {private Item item;private String itemName;}
public class Item {private String name;private int qty;}

Spring EL以XML形式

  • 使用 SpEL关闭的#{ SpEL expression }括号,请参阅XML bean定义文件下面的例子
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="itemBean" class="com.yiibai.core.Item"><property name="name" value="itemA" /><property name="qty" value="10" /></bean><bean id="customerBean" class="com.yiibai.core.Customer"><property name="item" value="#{itemBean}" /><property name="itemName" value="#{itemBean.name}" /></bean></beans>
  1. #{itemBean} – 注入"itemBean"到"customerBean"Bean 的"item"属性。
  2. #{itemBean.name} – 注入"itemBean"的"name"属性到 “customerBean” bean的"itemname"属性。

Spring EL以注解形式

在注解使用使用SpEL,必须通过注解注册您的组件。如果注册bean在XML和Java类中定义@Value,该@Value将无法执行

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component("customerBean")
public class Customer {@Value("#{itemBean}")private Item item;@Value("#{itemBean.name}")private String itemName;//...}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component("itemBean")
public class Item {@Value("itemA") //inject String directlyprivate String name;@Value("10") //inject interger directlyprivate int qty;public String getName() {return name;}//...
}

启用自动组件扫描

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="com.yiibai.core" /></beans>

在注解模式下,可以使用@Value定义Spring EL。在这种情况下,一个String和Integer值直接注入到“itemBean”,之后又注入“itemBean”到“customerBean”属性

执行输出

运行它,无论是使用 SpEL在XML 还是注释都显示了同样的结果:

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");Customer obj = (Customer) context.getBean("customerBean");System.out.println(obj);}
}

输出结果

Customer [item=Item [name=itemA, qty=10], itemName=itemA]
http://www.yayakq.cn/news/492293/

相关文章:

  • 网站建设工作情况汇报校园类网站模板免费下载
  • 餐饮网站建设思路在百度建免费网站
  • 宁波市网站集约化建设通知淄博网站制作设计高端
  • 英特尔网站开发框架雅昌网站做古董交易
  • 枞阳县建设局网站做分类信息网站如何
  • 德州市网站建设制作ppt的软件有哪些
  • 网页设计个人网站心得体会可拖拽 网站建设
  • 手机如何建立网站步骤襄樊网站建设襄樊
  • 什么网站可以做TCGA病理分期企业策划书格式
  • 有做彩票网站平台的吗网站域名注册哪家好
  • 网站建设需注意的问题影视公司注册
  • wordpress上传文件夹天津网站优化
  • 四川住房建设部官方网站网站seo外链怎么做
  • 前端网站开发心得体会小程序后端怎么搭建
  • 好的宝安网站建设网站建设案例公司
  • 百度站长推送sem竞价专员
  • 网站建设与维护期中试卷5成都网站建设
  • 网站有效内容的宣传及推广创建免费网站注意事项
  • 北京手机网站建设公司排名平台公司运营模式
  • wamp在网站建设中的功能及协作关系seo排名工具外包
  • 网站开发与spark网站开发学习案例
  • 西安网站挂标商城网站建设公司排行
  • 个人flash网站网站建设主要工作由哪些
  • 营销网站建设阿凡达北京网站维护浩森宇特
  • 做视频网站想用家庭网络保定cms建站系统
  • h5手机网站模板下载网站 chat now怎么做
  • 网站建设 教学设计游戏钓鱼网站开发
  • 网站代运营佛山商城网站制作
  • 湖州市南浔区建设局网站大连企业网站建设
  • 好的开源网站小程序源码多少钱