承接上文

引用其他对象或类型的成员


.net篇(环境为vs2012+Spring.Core.dll v1.31

public class Person {
public string Name { get; set; }
public static int Age { get; set; }
public string sex;
public static int Add(int x, int y){
return x + y;
}
public int Add(int x, int y,int z){
return x + y+z;
}
}
   <object id="person" type="SpringBase.Person,SpringBase">
<property name="Name" value="cnljli" />
<property name="Age" value="1"/>
<property name="sex" value="0"/>
</object>
<object id="theName"
type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="TargetObject" ref="person"/>
<property name="TargetProperty" value="Name"/>
</object>
<object id="theAge"
type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="StaticProperty" value="SpringBase.Person.Age"/>
</object>
<object id="thesex"
type="Spring.Objects.Factory.Config.FieldRetrievingFactoryObject, Spring.Core">
<property name="TargetObject" ref="person"/>
<property name="TargetField" value="sex"/>
</object>
<object id="theadd1"
type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject, Spring.Core">
<property name="TargetType" value="SpringBase.Person,SpringBase"/>
<property name="TargetMethod" value="Add"/>
<property name="Arguments">
<list>
<value>1</value>
<value>2</value>
</list>
</property>
</object>
<object id="theadd2"
type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject, Spring.Core">
<property name="TargetObject" ref="person"/>
<property name="TargetMethod" value="Add"/>
<property name="NamedArguments">
<dictionary>
<entry key="x" value="1" />
<entry key="y" value="2" />
<entry key="z" value="3" />
</dictionary>
</property>
</object>
  1. StaticProperty的值必须填完整
  2. Arguments的值的时候是从上往下匹配,NamedArguments是通过键值对匹配

java篇(环境为Maven+Jdk1.7+IntelliJ IDEA 12.1.4

package springdemo;
public class factoryObject {
private String name;
public static Integer age;
public String sex;
public static int Add(int x, int y) {
return x + y;
}
public static Integer getAge() {
return age;
}
public static void setAge(Integer age) {
factoryObject.age = age;
}
public int Add(int x, int y, int z) {
return x + y + z;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
    <bean id="person" class="springdemo.factoryObject">
<property name="name" value="cnljli"/>
<property name="age" value="1"/>
<property name="sex" value="0"/>
</bean>
<bean id="theName"
class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
<property name="targetBeanName" value="person"/>
<property name="propertyPath" value="name"/>
</bean>
<bean id="theAge"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField" value="springdemo.factoryObject.age"/>
</bean>
<bean id="thesex"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="TargetObject" ref="person"/>
<property name="targetField" value="sex"/>
</bean>
<bean id="theadd1"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="springdemo.factoryObject"/>
<property name="targetMethod" value="Add"/>
<property name="arguments">
<list>
<value>1</value>
<value>2</value>
</list>
</property>
</bean>
<bean id="theadd2"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="person"/>
<property name="targetMethod" value="Add"/>
<property name="arguments">
<list>
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
</bean>
  1. 字段必须有get和set的方法

javaCsharp的共同点

  1. theadd1是静态方法,theadd2为实例方法
  2. 就是标签的name几乎一样
  3. 分别的效果是获取属性、静态字段(csharp为静态属性)、获取字段、静态方法返回、实例方法返回

Ⅴ.spring的点点滴滴--引用其他对象或类型的成员的更多相关文章

  1. Ⅵ.spring的点点滴滴--自定义类型转换器

    承接上文 自定义类型转换器 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class CustomeConverter : TypeConverter{ ...

  2. Ⅳspring的点点滴滴--方法和事件

    承接上文 方法和事件 .net篇(环境为vs2012+Spring.Core.dll v1.31) public abstract class MethodDemo { protected abstr ...

  3. Java 超类引用子类对象的示例代码

    动态方法分配 dynamic method dispatch 一个被重写的方法的调用会在运行时解析,而不是编译时解析 Java 会根据在调用发生时引用的对象的类型来判断所要执行的方法 public c ...

  4. Ⅱ.spring的点点滴滴--对象

    承接上文 对象的各种实例化 .net篇(环境为vs2012+Spring.Core.dll) 修改原来的PersonDao对象为 public class PersonDao : IPersonDao ...

  5. Ⅹ.spring的点点滴滴--IObjectPostProcessor(对象后处理器)

    承接上文 IObjectPostProcessor(对象后处理器) 前提是实现接口的对象注册给当前容器 C#: 通过继承AbstractObjectFactory对象的AddObjectPostPro ...

  6. Ⅶ.spring的点点滴滴--自定义对象行为

    承接上文 自定义对象行为 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class lifeCycle : Spring.Objects.Factory. ...

  7. Ⅷ.spring的点点滴滴--抽象对象和子对象

    承接上文 抽象对象和子对象 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class parent { public string Name { get; ...

  8. Spring根据XML配置文件注入对象类型属性

    这里有dao.service和Servlet三个地方 通过配过文件xml生成对象,并注入对象类型的属性,降低耦合 dao文件代码: package com.swift; public class Da ...

  9. Ⅲ.spring的点点滴滴--赋值

    承接上文 对象的赋值(调用方式都一样不再阐述) .net篇(环境为vs2012+Spring.Core.dll v1.31) public class PropertyDemo{ public Sys ...

随机推荐

  1. UIMenuController搭配UIPasteboard,执行拷贝-黏贴操作-b

    一.基本概念 UIKit框架中,可以直接执行拷贝黏贴操作的有:UITextView.UITextField和UIWebView,其他控件需要实现相关方法. 关于UIPasteboard ·黏贴板是ap ...

  2. Pentaho Data Integration笔记 (四):Kitchen

    官方网站: http://wiki.pentaho.com/display/EAI/Kitchen+User+Documentation Kitchen Kitchen是一个可以执行Spoon编辑的J ...

  3. hdu 3717

    思路:二分答案,然后模拟消灭石头的过程: 如果单纯的暴力模拟的话,肯定会T的: 所以要用到一定的技巧来维护: 在网上看到大神们用O(n)的复杂度来优化,真心orz: 原理是这样的:用一个变量sum_2 ...

  4. Swift 中的 Runtime

    即使在 Swift APP 中没有一行 Object-c 的代码,每个 APP 也都会在 Object-c runtime 中运行,为动态任务分发和运行时对象关联开启了一个世界.更确切地说,可能在仅使 ...

  5. HDU4519

    一种比较挫的写法 /* 模拟 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...

  6. 查看java的.class文件的方法

    在不通过eclipse等IDE安装反编译插件的情况下查看java的.class文件的方法:可以通过下载jd-gui class文件查看工具进行查看.如附件的“jd-gui.exe”程序. 1. 从网上 ...

  7. cocos2d-html5 Layer 和 Scene 创建模式

    var myLayer = cc.Layer.extend({ init:function() {//2 界面 var bRet = false; if (this._super()) { bRet ...

  8. MySQL的SQL_CALC_FOUND_ROWS

    分页程序一般由两条SQL组成: SELECT COUNT(*) FROM ... WHERE .... SELECT ... FROM ... WHERE LIMIT ... 如果使用SQL_CALC ...

  9. BZOJ3166: [Heoi2013]Alo

    3166: [Heoi2013]Alo Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 394  Solved: 204[Submit][Status] ...

  10. BZOJ1895: Pku3580 supermemo

    1895: Pku3580 supermemo Time Limit: 15 Sec  Memory Limit: 64 MBSubmit: 77  Solved: 47[Submit][Status ...