免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1161 | 回复: 0
打印 上一主题 下一主题

面向接口编程实践使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-27 13:41 |只看该作者 |倒序浏览

                下面就举SSH的例子来进行详细的説明:
登陆的Action:
1.控制层
(1).LoginAction:
   只需要导入登陆的ILoginService接口
eg:
   ILoginService loginService;
    private Admin admin = null;
    public String adminLogin() {
        Admin _admin = loginService.adminLogin(admin.getAdminAccount(), admin
                .getPassword());
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        if (_admin != null) {
                session.removeAttribute("adminObj");
                session.setAttribute("adminObj", _admin);
                return SUCCESS;
        } else {
            return FLASE;
        }
   }
      
2.业务逻辑层
(1).登陆接口ILoginService的详细代码:
eg:
public interface ILoginService {
   
Admin adminLogin(String adminAccount, String password);
}
(2).登陆LoginService的详细代码:
eg:
public class LoginService implements ILoginService{
     ILoginDao loginDao;
    public ILoginDao getLoginDao() {
        return loginDao;
    }
    public void setLoginDao(ILoginDao loginDao) {
        this.loginDao = loginDao;
    }
    public Admin adminLogin(String adminAccount, String password) {
        
        return loginDao.adminLogin(adminAccount, password);
    }
}
3.数据访问层:
(1)登陆接口ILoginDao
eg:
public interface ILoginDao {
    Admin adminLogin(String adminAccount, String password);
}
(2)登陆DAO-loginDao

public class LoginDao extends HibernateDaoSupport implements ILoginDao{
    public Admin adminLogin(String adminAccount, String password) {
        String hql = "from Admin as admin where admin.adminAccount='"
                + adminAccount + "' and admin.password='" + password + "'";
        List list = this.getHibernateTemplate().find(hql);
        return (list.size() != 0) ? ((Admin) list.get(0)) : null;
    }
}
4.Spring配置文件
(1)(登陆的配置文件)-applicationContext_login.xml
eg:
   
        
            
        
   
   
   
        
            
               
                    
               
            
        
   
   
        
            
        
   
(2)总的Spring配置文件
   
     
        
        
        
        
        
        
        
        
        
        
   
   
   
   
   
   
        
            
        
        
            
        
        
            
                classpath:com/itanger/domain/
            
        
        
            
               
                    org.hibernate.dialect.MySQLDialect
               
                true
            
        
   
   
   
   
        
            
        
   
   
   
        
            
        
        
            
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED, readOnly
            
        
   

5.web.xml
    SSH配置系统
   
        jsp/start.jsp
   
   
        log4jConfigLocation
        /WEB-INF/classes/log4j.xml
   
   
        contextConfigLocation
        /WEB-INF/applicationContext*.xml
   
    struts2
   
    struts2
    org.apache.struts2.dispatcher.FilterDispatcher
   
     
        struts2
        /*
     
   
        struts-cleanup
        
            org.apache.struts2.dispatcher.ActionContextCleanUp
        
   
   
        struts-cleanup
        /*
   
   
        action2
        
            org.apache.struts2.dispatcher.FilterDispatcher
        
   
   
        action2
        *.action
   
   
        action2
        *.jsp
   
   
   
        
            org.springframework.web.context.ContextLoaderListener
        
   
   
        
            org.springframework.web.util.Log4jConfigListener
        
   
以上的学习,你基本上对面向借口编程和SSH有了一点的了解,其中面向接口编程为什么好,为什么适用了面向接口后,对以后的维护有帮助,对代码的修改有帮助,这个你就在日常的工作中慢慢的体会吧,多说不益。。。。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/55633/showart_1881830.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP