熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Struts2的類型轉換[2]

2022-06-13   來源: Java開源技術 

  建立實現邏輯控制類

//Action控制類:OgnlTypeConvertjava
package cneduhld;

import comopensymphonyxworkActionSupport;

public class OgnlTypeConvert extends ActionSupport
{
private User user ;

public User getUser()
{
return user;
}

public void setUser(User user)
{
thisuser = user;
}
public String execute()
{
if(thisgetUser()getUserName()equals(thtwin) &&
thisgetUser()getUserPass()equals(thtwinjee) )
{
return SUCCESS ;
}
else
{
return ERROR ;
}
}
}

  實現類型轉換的核心類

//類型轉換核心類

package cneduhld;

import javautilMap;

import ognlDefaultTypeConverter;

public class TypeConversion extends DefaultTypeConverter
{

@Override
public Object convertValue(Map context Object values Class toClass)
{

if(toClass == Userclass)
{
String strUser[] = (String[])values ;
String userInfo[] = strUser[]split() ;
User user = new User() ;
usersetUserName(userInfo[]) ;
usersetUserPass(userInfo[]) ;
return user ;
}

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29167.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.