原文来源:http://blog.youkuaiyun.com/yuan_xw/article/details/7838123
在不同的类之间传递参数,除了通过new的方法得到这个类,或者是得到bean的方法外,还可以通过定义常量或者变量的形式。
比如我们在某个类里定义了一个静态变量:
// 缓存请假对象
public static Map<String,Integer[]> existsLeaveMap = new HashMap<String,Integer[]>();
然后写一个方法去数据库里查询,将其写入静态变量
/**
* 判断是否存在请假
* @param bean
* @param date
* @return
*/
public Integer[] existsLeave(OAAttendance bean,java.sql.Date date){
Integer attType[] = existsLeaveMap.get("key");
if(attType == null){
AttendanceRuleDao ard = AttendanceDaoInstance.getAttendanceRuleDaoInstance();
attType = ard.getExistData(bean.getUserNo(), date);
existsLeaveMap.put("key", attType);
}
return attType;
}
在别的类里用的时候,直接用类名调这个方法就可以了。
本文介绍了一种在不同类间传递参数的方法,即利用静态变量实现数据共享。通过定义一个静态Map来缓存请假对象,并提供一个方法用于查询和更新缓存数据。此方法避免了频繁访问数据库,提高了应用效率。
1万+

被折叠的 条评论
为什么被折叠?



