好文档 - 专业文书写作范文服务资料分享网站

整合struts1+spring+hibernate框架完成简单的登录

天下 分享 时间: 加入收藏 我要投稿 点赞

public class LoginForm extends ValidatorForm { /* * Generated fields */ /** userName property */ private String userName; /** userPassword property */ private String userPassword; /* * Generated Methods */ /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub return null; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub } /** * Returns the userName. * @return String */ public String getUserName() { return userName; } /** * Set the userName. * @param userName The userName to set */ public void setUserName(String userName) { this.userName = userName; } /** * Returns the userPassword. * @return String */ public String getUserPassword() { return userPassword; } /** * Set the userPassword. * @param userPassword The userPassword to set */ public void setUserPassword(String userPassword) { this.userPassword = userPassword; } }

13.创建完成的ILoginBusiness.java文件: package com.login.business; import com.login.entity.TestUser; import com.login.form.LoginForm; public interface ILoginBusiness { public TestUser getUsers(LoginForm loginForm); } 14.创建完成的LoginBusinessImpl.java文件: package com.login.business.impl; import com.login.business.ILoginBusiness; import com.login.dao.impl.ILoginDao; import com.login.entity.TestUser; import com.login.form.LoginForm; public class LoginBusinessImpl implements ILoginBusiness { private ILoginDao iLoginDao; public ILoginDao getILoginDao() { return iLoginDao; } public void setILoginDao(ILoginDao loginDao) { iLoginDao = loginDao; } public TestUser getUsers(LoginForm loginForm) { } // TODO Auto-generated method stub String userName=loginForm.getUserName(); String userPassword=loginForm.getUserPassword(); TestUser users=new TestUser(); users.setUserName(userName); users.setUserPassword(userPassword); return iLoginDao.getUsers(users); } 15.创建完成的ILoginDao.java文件: package com.login.dao.impl; import com.login.entity.TestUser; public interface ILoginDao{ public TestUser getUsers(TestUser users); } 16.创建完成的LoginDaoImpl.java文件: package com.login.dao.impl; import java.util.List; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.login.entity.TestUser; public class LoginDaoImpl extends HibernateDaoSupport implements ILoginDao { @SuppressWarnings(\) public TestUser getUsers(TestUser users) { // TODO Auto-generated method stub try { String hql=\TestUser where userName='\+users.getUserName()+\and userPassword='\+users.getUserPassword()+\; List userList = this.getHibernateTemplate().find(hql); if(userList.size()>0){ TestUser testUser = (TestUser)userList.get(0); return testUser; } } catch (DataAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null;} } 17.修改整理过的TestUser.hbm.xml文件: 18.修改spring配置文件:applicationContext.xml

(1)增加AOP事务 (2)注入工具类 (3)注入数据层

(4)注入业务层 (5)注入控制层

完成修改之后的配置文件:

org.hibernate.dialect.Oracle9Dialect com/login/entity/TestUser.hbm.xml

整合struts1+spring+hibernate框架完成简单的登录

publicclassLoginFormextendsValidatorForm{/**Generatedfields*//**userNameproperty*/privateStringuserName;/**
推荐度:
点击下载文档文档为doc格式
3r2256ssr78jj329nai7
领取福利

微信扫码领取福利

微信扫码分享