回調,有什么好處呢,是一種設計模式嗎?
只是在hibernate當中的template當中會使用到。例如以下:
- public?int?executeUpdate(final?String?hql,?final?Map?pMap)?{??
- ????????int?result?=?0;??
- ????????Object?o?=?getHibernateTemplate().execute(new?HibernateCallback()?{??
- ????????? //實現HibernateCall接口當中的方法,自己實現接口當中的方法的
- ???????? //具體業務流程
- ????????????public?Object?doInHibernate(final?Session?session)??
- ????????????????????throws?HibernateException?{??
- ??????????????????? int?result?=?0;??
- ???????????????????? Query?queryObject?=?session.createQuery(hql);??
- ???????????????????? String[]?params?=?queryObject.getNamedParameters();??
- ?????????????????????
- ?????????????????????? for?(int?i?=?0,?max?=?params.length;?i?<?max;?i++)?{??
- ??????????????????????????? queryObject.setParameter(params[i],?pMap.get(params[i]));??
- ????????????????????? }??
- ?????????????????????
- ?????????????????????? ?result?=?queryObject.executeUpdate();??
- ?????????????????????? ?return?result;??
- ??????????????}??
- ????????});??//end of method execute()
- ???????
- ????????Integer?i?=?(Integer)?o;??
- ????????result?=?i.intValue();??
- ????????return?result;??
- ????}?
???使用hibernate模板類當中的方法。
。。。。。。。。。未完待續。
posted on 2009-05-19 17:21
JavaCoffe 閱讀(156)
評論(0) 編輯 收藏 所屬分類:
J2SE基礎學習