分类: 系统运维
2012-01-22 13:40:20
Struts2应用的分层体系架构:
action-->service(接口)-->DAO
------------------------------------------------------
LoginService (interface):
public interface LoginService
{
public boolean isLogin(String username,String password);
}
LoginServiceImpl.java
package com.shengsiyuan.impl;
import com.shengsiyuan.service.LoginService;
import com.sun.org.apache.regexp.internal.recompile;
public class LoginServiceImpl implements LoginService
{
public boolean isLogin(String username, String password)
{
if("hello".equals(username) && "world".equals(password))
{
return true ;
}
return false ;
}
}
LoginAction.java
private LoginService loginService = new LoginServiceImpl() ;
public String execute() throws Exception //有业务逻辑的验证放在这里,而不放在validate里
{
if(this.loginService.isLogin(username, password))
{
return SUCCESS ;
}
return INPUT ;
}
struts.xml