面试题:请描述出与之等效的Java语句??
<bean id= "studentDao " class= "oe.spring.StudentDaoImpl ">
<property name= "school ">
<value> shida </value>
</property>
<property name= "address ">
<value> cangshan </value>
</property>
<property name= "mark ">
<list>
<value> 90 </value>
<value> 80 </value>
<value> 50 </value>
</list>
</bean>
------解决方案--------------------应该是这样的吧,这是一个Spring的BeanFactory配置文件生成一个StudentDaoImpl单例对象
public BeanFactory
{
private static StudentDaoImpl dao;
private DaoFactory(){}
public static StudentDaoImpl getDao(){
if(dao == null){
dao = new StudentDaoImpl()
dao.setSchool( "shida ");
dao.setAddress( "cangshan ");
List list = new ArrayList();
list.add(new Integer(90));
list.add(new Integer(80));
list.add(new Integer(50));
dao.setMark(list);
}
return dao;
}
}
------解决方案--------------------yun
虽然我spring不太会
但是明显看的出这是Spring的属性拄入!
spring ioc机制和aop是两大特点!
这正是ioc
import java.util.ArrayList;
import java.util.List;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
StudentDaoImpl student = new StudentDaoImpl();
student.setSchool( "shida ");
student.setAddress( "cangshan ");
List list = new ArrayList();
list.add(90);
list.add(80);
list.add(50);
student.setMark(list);
}
}
class StudentDaoImpl {
private String school;
private String address;
private List mark;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public List getMark() {
return mark;
}
public void setMark(List mark) {
this.mark = mark;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
}
------解决方案--------------------上面的太谦虚了!
------解决方案--------------------轻量级的Spring技术在一定程度上改变了我们传统意义上的Java编程模式.基于配置模式的脚本编程.这种改变给我们的编程带来了很多的好处,比如:代码间的耦合度更小,具有组件式的差拔特性,更好管理工程模块.
import java.util.ArrayList;
import java.util.List;
public class Util {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
StudentDaoImpl student = new StudentDaoImpl();
student.setSchool( "shida ");
student.setAddress( "cangshan ");
List list = new ArrayList();
list.add(90);
list.add(80);
list.add(50);
student.setMark(list);
}
}
class StudentDaoImpl{},set和get方法在spring 注入时生成!!