Ⅴ.spring的点点滴滴--引用其他对象或类型的成员
承接上文
引用其他对象或类型的成员
.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>
- StaticProperty的值必须填完整
- 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>
- 字段必须有get和set的方法
java和Csharp的共同点
- theadd1是静态方法,theadd2为实例方法
- 就是标签的name几乎一样
- 分别的效果是获取属性、静态字段(csharp为静态属性)、获取字段、静态方法返回、实例方法返回
Ⅴ.spring的点点滴滴--引用其他对象或类型的成员的更多相关文章
- Ⅵ.spring的点点滴滴--自定义类型转换器
承接上文 自定义类型转换器 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class CustomeConverter : TypeConverter{ ...
- Ⅳspring的点点滴滴--方法和事件
承接上文 方法和事件 .net篇(环境为vs2012+Spring.Core.dll v1.31) public abstract class MethodDemo { protected abstr ...
- Java 超类引用子类对象的示例代码
动态方法分配 dynamic method dispatch 一个被重写的方法的调用会在运行时解析,而不是编译时解析 Java 会根据在调用发生时引用的对象的类型来判断所要执行的方法 public c ...
- Ⅱ.spring的点点滴滴--对象
承接上文 对象的各种实例化 .net篇(环境为vs2012+Spring.Core.dll) 修改原来的PersonDao对象为 public class PersonDao : IPersonDao ...
- Ⅹ.spring的点点滴滴--IObjectPostProcessor(对象后处理器)
承接上文 IObjectPostProcessor(对象后处理器) 前提是实现接口的对象注册给当前容器 C#: 通过继承AbstractObjectFactory对象的AddObjectPostPro ...
- Ⅶ.spring的点点滴滴--自定义对象行为
承接上文 自定义对象行为 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class lifeCycle : Spring.Objects.Factory. ...
- Ⅷ.spring的点点滴滴--抽象对象和子对象
承接上文 抽象对象和子对象 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class parent { public string Name { get; ...
- Spring根据XML配置文件注入对象类型属性
这里有dao.service和Servlet三个地方 通过配过文件xml生成对象,并注入对象类型的属性,降低耦合 dao文件代码: package com.swift; public class Da ...
- Ⅲ.spring的点点滴滴--赋值
承接上文 对象的赋值(调用方式都一样不再阐述) .net篇(环境为vs2012+Spring.Core.dll v1.31) public class PropertyDemo{ public Sys ...
随机推荐
- JAVA入门第二季(mooc-笔记)
相关信息 /** * @subject <学习与创业>作业1 * @author 信管1142班 201411671210 赖俊杰 * @className <JAVA入门第二季&g ...
- nodejs 第一次使用
在win7下安装与使用 1 nodejs官网下载,安装 https://nodejs.org/ 2 下载最新的 npm,在E:\nodejs\中解压 http://nodejs.org/dist/ ...
- JDBC之PreparedStatement模糊查询
今天要做一个关于模糊查询的需求,以前用JDBC做精确查询都是用 "SELECT * FROM test WHERE id = ?",所以用模糊查询时理所当然的也用了"SE ...
- mysql查询结果中文显示成了问号
在mysql的配置文件my.ini中的[mysqld]项中加这两句 character-set-server = utf8 collation-server = utf8_general_ci 在任务 ...
- jQuery CSS 添加/删除类名
addClass(class) — 为每个匹配的元素添加指定的类名.参数 : class — 一个或多个要添加到元素中的CSS类名,请用空格分开(String)示例 一 :为匹配的元素加上 'sele ...
- UVA 11734 Big Number of Teams will Solve This
大水题,不解释啦! #include<cstdio> #include<cstring> #define maxn 50 using namespace std; char s ...
- php访问类静态属性
在类的外部,如果要使用到类的静态变量,则可以使用 :: 操作符. <?php class A { static $x = 10; function test() { echo self::$x; ...
- c helloworld on zynq
A linux os runs on zynq board. I want ro run a hello world c program on it. I linked zynq board to a ...
- 数据库 一致性读&&当前读
今天小伙伴问了一个sql的问题: update t set status=2 where id in(select id from t where status=1) 这个sql,在并发的情况下,会不 ...
- FreeBSD方式安装 MAC OSX
首先你的电脑需要支持硬件虚拟化,可以用securable进行检测,如图所示即为支持,说明可以再你电脑的虚拟机里面安装苹果系统,如果有其中一项为NO,那么不好意思,你就没法安装了 2 其次你的电脑要提前 ...