pointcutid="allManagerMethod"
expression="execution(*com.hubu.service.*.*(..))"/>
advisoradvice-ref="txAdvice"pointcut-ref="allManagerMethod"/>
config>
7.此时我们算是基本完成了ssh框架的整合,我们来做一个测试,看看刚才我们的整合是不是正确的。
就以userInfo这个表为例来讲述他的curd操作
我们在src下建立如下所示的包
然分别在相应的包中放置相应的方法和类
逆向生成实体类:
其中实现功能的代码如下所示:
userDao接口
packagecom.hubu.dao;
importjava.util.List;
importcom.hubu.entity.UserInfo;
publicinterfaceuserInfoDao{
publicvoidsaveUserInfo(UserInfouserInfo);
publicvoiddeleteUserInfo(Longid);
publicvoidupdateUerInfo(UserInfouserInfo);
publicUserInfofindById(Longid);
publicListlistUserInfo();
}
userInfoDaoImpl类
packagecom.hubu.daoImpl;
importjava.util.List;
importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;
importcom.hubu.dao.userInfoDao;
importcom.hubu.entity.UserInfo;
publicclassUserInfoDaoImplextendsHibernateDaoSupportimplementsuserInfoDao{
publicvoiddeleteUserInfo(Longid){
//TODOAuto-generatedmethodstub
this.getHibernateTemplate().delete(this.getHibernateTemplate().get(UserInfo.class,id));
}
publicUserInfofindById(Longid){
//TODOAuto-generatedmethodstub
returnthis.getHibernateTemplate().get(UserInfo.class,id);
}
publicListlistUserInfo(){
//TODOAuto-generatedmethodstub
returnthis.getHibernateTemplate().find("fromUserInfo");
}
publicvoidsaveUserInfo(UserInfouserInfo){
//TODOAuto-generatedmethodstub
this.getHibernateTemplate().save(userInfo);
}
publicvoidupdateUerInfo(UserInfouserInfo){
//TODOAuto-generatedmethodstub
this.getHibernateTemplate().update(userInfo);
}
}
userService接口
packagecom.hubu.service;
importjava.util.List;
importcom.hubu.entity.UserInfo;
publicinterfaceUserInfoService{
publicvoidsaveUserInfo(UserInfouserInfo);
publicvoiddeleteUserInfo(Longid);
publicvoidupdateUerInfo(UserInfouserInfo);
publicUserInfofindById(Longid);
publicListlistUserInfo();
}
packagecom.hubu.serviceImpl;
importjava.util.List;
importcom.hubu.dao.UserInfoDao;
importcom.hubu.entity.UserInfo;
importcom.hubu.service.UserInfoService;
publicclassUserInfoServiceImplimplementsUserInfoService{
privateUserInfoDaouserInfoDao;
publicvoiddeleteUserInfo(Longid){
//TODOAuto-generatedmethodstub
this.getUserInfoDao().deleteUserInfo(id);
}
publicUserInfofindById(Longid){
//TODOAuto-generatedmethodstub
returnthis.getUserInfoDao().findById(id);
}
publicListlistUserInfo(){
//TODOAuto-generatedmethodstub
returnthis.getUserInfoDao().listUserInfo();
}
publicvoidsaveUserInfo(UserInfouserInfo){
//TODOAuto-generatedmethodstub
this.getUserInfoDao().saveUserInfo(userInfo);
}
publicvoidupdateUerInfo(UserInfouserInfo){
//TODOAuto-generatedmethodstub
}
publicvoidsetUserInfoDao(UserInfoDaouserInfoDao){
this.userInfoDao=userInfoDao;
}
publicUserInfoDaogetUserInfoDao(){
returnuserInfoDao;
}
}
对应的action类
packagecom.hubu.action;
importjava.util.List;
importcom.hubu.entity.UserInfo;
importcom.hubu.service.UserInfoService;
importcom.opensymphony.xwork2.ActionSupport;
publicclassUserInfoActionextendsActionSupport{
privateUserInfouserInfo;
privateUserInfoServiceuserInfoService;
privateLongid;
privateListlistAllInfos;
publicvoidsetUserInfo(UserInfouserInfo){
this.userInfo=userInfo;
}
publicUserInfogetUserInfo(){
returnuserInfo;
}
publicvoidsetUserInfoService(UserInfoServiceuserInfoService){
this.userInfoService=userInfoService;
}
publicUserInfoServicegetUserInfoService(){
returnuserInfoService;
}
publicvoidsetId(Longid){
this.id=id;
}
publicLonggetId(){
returnid;
}
publicvoidsetListAllInfos(ListlistAllInfos){
this.listAllInfos=listAllInfos;
}
publicListgetListAllInfos(){
returnlistAllInfos;
}
publicStringsaveUserInfo()throwsException{
try{
this.userInfoService.saveUserInfo(userInfo);
}catch(Exceptione){
//TODO:
handleexception
e.printStackTrace();
returnINPUT;
}
returnSUCCESS;
}
publicStringdeleteUserInfo()throwsException{
try{
this.userInfoService.deleteUserInfo(id);
}catch(Exceptione){
//TODO:
handleexception
e.printStackTrace();
returnINPUT;
}
returnSUCCESS;
}
publicStringfindById()throwsException{
try{
userInfo=this.userInfoService.findById(id);
}catch(Exceptione){
//TODO:
handleexception
e.printStackTrace();
returnINPUT;
}
returnSUCCESS;
}
publicStringlistAllUer()throwsException{
try{
listAllInfos=this.userInfoService.listUserInfo();
}catch(Exceptione){
//TODO:
handleexception
e.printStackTrace();
returnINPUT;
}
returnSUCCESS;
}
}
配置stucts2
listUserInfo.action
/error.jsp
listUserInfo.action
/error.jsp
listUserInfo.action
/error.jsp
/web/user/userModify.jsp
/error.jsp
/web/user/listUerInfo.jsp
/error.jsp
8.建立相应的jsp文件
添加页面
列出已经添加的信息
嗯,总的算是成功了。
。
无论布局如何,,若是有什么不对的地方,希望大家能给与指正,谢谢。
。
。