new framework(8)--import static

new framework(8)--import static

现在J2SE 5.0提供了静态导入的功能,你只需要在import关键字后面写一个static关键字就可以直接
使用类中定义的常量了,例如

import static afu.framework.util.Constant.CURRENT_USER;
import static afu.framework.util.Constant.EXCEPTION_MESSAGE;

     public  String login()
    
{
        String userId 
= getParaValue("userid");
        String password 
= getParaValue("password");
        String remoteIp 
= request.getRemoteAddr();
        UserDto dto 
= ((SysService)service).login(userId, password, remoteIp);
        
        
if(dto==null)
        
{
            request.setAttribute(EXCEPTION_MESSAGE,
"用户名或密码不对");
            
return null;
        }

        request.setAttribute(CURRENT_USER,dto);
        
return "/common/index.jsp";
    }


而没有这个功能之前,我们得这么写
request.setAttribute(Constant.EXCEPTION_MESSAGE,"用户名或密码不对");

你可能感兴趣的:(new framework(8)--import static)