如何实现三个模块良好的切换?
配置文件
<beans> <bean id="dao" class="dao.CustomerDao"></bean> <!-- 将dao装配到DaoCaller内dao属性 --> <bean id="caller" class="caller.DaoCaller"> <property name="dao"> <ref local="dao"/> </property> </bean>
</beans> |
程序
package dao;
public interface IDAO { public boolean login(String account,String password); }
package dao;
public class StudentDao implements IDAO {
public boolean login(String account, String password) { System.out.println("Student登陆,账号:" + account + " 密码:" + password); return false; } }
package dao;
public class CustomerDao implements IDAO {
public boolean login(String account, String password) { System.out.println("Customer登陆,账号:" + account + " 密码:" + password); return false; }
}
package caller;
import dao.IDAO;
public class DaoCaller { private IDAO dao;//设置成为一个属性 public IDAO getDao() { return dao; } public void setDao(IDAO dao) { this.dao = dao; } public void callDao(String account,String password){ dao.login(account, password); } }
package main;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;
import caller.DaoCaller;
public class MainModule {
public static void main(String[] args) { ApplicationContext context = new FileSystemXmlApplicationContext("applicationContext.xml"); DaoCaller caller = (DaoCaller)context.getBean("caller"); caller.callDao("111", "34;gd");
}
} |