最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring實(shí)戰(zhàn)之Bean定義中的SpEL表達(dá)式語言支持操作示例

 更新時(shí)間:2019年12月11日 12:05:13   作者:cakincqm  
這篇文章主要介紹了Spring實(shí)戰(zhàn)之Bean定義中的SpEL表達(dá)式語言支持操作,結(jié)合實(shí)例形式分析了Bean定義中的SpEL表達(dá)式語言操作步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Spring實(shí)戰(zhàn)之Bean定義中的SpEL表達(dá)式語言支持操作。分享給大家供大家參考,具體如下:

一 配置

<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的根元素和Schema
   導(dǎo)入p:命名空間和util:命名空間的元素 -->
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util-4.0.xsd">
   <!-- 使用util.properties加載指定資源文件 -->
   <util:properties id="confTest"
      location="classpath:test_zh_CN.properties"/>
   <!--
   配置setName()的參數(shù)時(shí),在表達(dá)式中調(diào)用方法
   配置setAxe()的參數(shù)時(shí),在表達(dá)式中創(chuàng)建對(duì)象
   配置調(diào)用setBooks()的參數(shù)時(shí),在表達(dá)式中訪問其他Bean的屬性 -->
   <bean id="author" class="org.crazyit.app.service.impl.Author"
      p:name="#{T(java.lang.Math).random()}"
      p:axe="#{new org.crazyit.app.service.impl.SteelAxe()}"
      p:books="#{ {confTest.a , confTest.b} }"/>
</beans>

二 資源文件

a=\u300a\u8f7b\u91cf\u7ea7Java EE\u4f01\u4e1a\u5e94\u7528\u5b9e\u6218\u300b
b=\u300a\u75af\u72c2Java\u8bb2\u4e49\u300b

三 接口

Axe

package org.crazyit.app.service;
public interface Axe
{
   String chop();
}

Person

package org.crazyit.app.service;
import java.util.*;
public interface Person
{
   public void useAxe();
   public List<String> getBooks();
   public String getName();
}

四 Bean

Author

package org.crazyit.app.service.impl;
import java.util.*;
import org.crazyit.app.service.*;
public class Author implements Person
{
  private Integer id;
  private String name;
  private List<String> books;
  private Axe axe;
  // id的setter和getter方法
  public void setId(Integer id)
  {
    this.id = id;
  }
  public Integer getId()
  {
    return this.id;
  }
   // name的setter和getter方法
  public void setName(String name)
  {
    this.name = name;
  }
  public String getName()
  {
    return this.name;
  }
   // books的setter和getter方法
  public void setBooks(List<String> books)
  {
    this.books = books;
  }
  public List<String> getBooks()
  {
    return this.books;
  }
   // axe的setter方法
  public void setAxe(Axe axe)
  {
    this.axe = axe;
  }
   public void useAxe()
  {
    System.out.println("我是"
      + name + ",正在砍柴\n" + axe.chop());
  }
}

SteelAxe

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class SteelAxe implements Axe
{
   public String chop()
   {
      return "鋼斧砍柴很快!";
   }
}

五 測(cè)試類

package lee;
import org.springframework.context.*;
import org.springframework.context.support.*;
import java.util.*;
import org.crazyit.app.service.*;
public class SpELTest
{
  public static void main(String[] args)
  {
    ApplicationContext ctx = new
      ClassPathXmlApplicationContext("beans.xml");
    Person author = ctx.getBean("author" , Person.class);
    System.out.println(author.getBooks());
    author.useAxe();
   }
}

六 測(cè)試結(jié)果

[《輕量級(jí)Java EE企業(yè)應(yīng)用實(shí)戰(zhàn)》, 《瘋狂Java講義》]
我是0.06178107142599454,正在砍柴
鋼斧砍柴很快!

更多關(guān)于java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Spring框架入門與進(jìn)階教程》、《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Java操作DOM節(jié)點(diǎn)技巧總結(jié)》、《Java文件與目錄操作技巧匯總》和《Java緩存操作技巧匯總

希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • SpringSecurity在分布式環(huán)境下的使用流程分析

    SpringSecurity在分布式環(huán)境下的使用流程分析

    文章介紹了Spring?Security在分布式環(huán)境下的使用,包括單點(diǎn)登錄(SSO)的概念、流程圖以及JWT(JSON?Web?Token)的生成和校驗(yàn),通過使用JWT和RSA非對(duì)稱加密,可以實(shí)現(xiàn)安全的分布式認(rèn)證,感興趣的朋友一起看看吧
    2025-02-02
  • 最新評(píng)論

    蒙城县| 隆德县| 长顺县| 海晏县| 桓台县| 厦门市| 曲水县| 彰化县| 抚宁县| 麦盖提县| 治多县| 阿城市| 格尔木市| 纳雍县| 新源县| 改则县| 长宁县| 丹江口市| 梁河县| 车险| 荃湾区| 罗平县| 黑水县| 高碑店市| 永修县| 香河县| 互助| 黎城县| 临颍县| 奇台县| 葫芦岛市| 乌海市| 五莲县| 体育| 陆良县| 长白| 郯城县| 呈贡县| 无为县| 湟中县| 牙克石市|