回調(diào),有什么好處呢,是一種設(shè)計(jì)模式嗎?
只是在hibernate當(dāng)中的template當(dāng)中會(huì)使用到。例如以下:
- public?int?executeUpdate(final?String?hql,?final?Map?pMap)?{??
- ????????int?result?=?0;??
- ????????Object?o?=?getHibernateTemplate().execute(new?HibernateCallback()?{??
- ????????? //實(shí)現(xiàn)HibernateCall接口當(dāng)中的方法,自己實(shí)現(xiàn)接口當(dāng)中的方法的
- ???????? //具體業(yè)務(wù)流程
- ????????????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模板類當(dāng)中的方法。
。。。。。。。。。未完待續(xù)。