早安,
我在英语(:D)和GWT方面遇到很多问题。
在GWT中,抽象类可以序列化吗?
这是我有关ElectionOnline的项目代码。非常感谢您的帮助。
package elezione.eco.shared;
public abstract class User
{
protected String username;
protected String password;
protected String email;
protected String name;
protected String surname;
protected String sex;
protected String birthDate;
protected String birthPlace;
protected String address;
public User(){}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public String getSex() {
return sex;
}
public String getBirthDate() {
return birthDate;
}
public String getBirthPlace() {
return birthPlace;
}
public String getAddress() {
return address;
}
public String getUsername(){
return username;
}
public String getPassword(){
return password;
}
public String getEmail(){
return email;
}
}
package elezione.eco.server;
import elezione.eco.client.ECOService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import elezione.eco.shared.*;
import java.io.File;
import java.util.ArrayList;
import org.mapdb.DB;
import org.mapdb.DBMaker;
/**
* The server-side implementation of the RPC service.
*/
public class ECOServiceImpl extends RemoteServiceServlet implements ECOService {
private static final long serialVersionUID = 1L;
LoginServiceImpl loginService;
public ECOServiceImpl() {
DB db = DBMaker.newFileDB( new File( "ECO-DB.txt" ) ).closeOnJvmShutdown().make();
loginService = new LoginServiceImpl( db );
}
public void restartDb() {
loginService.clear();
loginService.addAdmin();
}
public void populate() {
try {
addUser( "Sergio" , "m" , "sergio@studio.it" , null , null , null , null , null , null );
} catch ( DuplicatedUserNameException e ) {
e.printStackTrace();
}
}
public User addUser( String username, String password, String email, String name, String surname, String sex,
String birthDate, String birthPlace, String address ) throws DuplicatedUserNameException {
return loginService.addUser( username , password , email , name , surname , sex , birthDate , birthPlace ,
address );
}
public User login( String userName, String password ) throws WrongPasswordException, UserNotFoundException {
return loginService.login( userName , password );
}
public ArrayList<User> getRegistered() {
return loginService.getRegistered();
}
public ArrayList<User> getAllUsers() {
return loginService.getAllUsers();
}
}
好吧,我不明白,因为gwt带有可序列化的编译错误。类摘要可以序列化吗?我必须实现模式抽象。谢谢
答案 0 :(得分:1)
GWT(具体来说是GWT-RPC)支持对继承了抽象可序列化类的IsSerializable类进行序列化。
如果您要在客户端上查找没有特定实现的DTO类,则需要Proxy
或RequestFactory
http://www.gwtproject.org/doc/latest/DevGuideRequestFactory.html