我已經試過你的代碼,它的工作很好,但有一些小的改動。
有在你的代碼中的一些編輯錯誤,以及,可能是由於錯字的錯誤,如:
GetItemRequest<T extends FooBase>
public class GetServiceImpl<T extends FooBase> extends RemoteServiceServlet implements GetService
請從下面的代碼,以再次驗證:
共享:
public abstract class GetItemRequest<T extends FooBase> {
public abstract long getId();
}
import com.google.gwt.user.client.rpc.IsSerializable;
public class GetFooRequest extends GetItemRequest<Foo> implements IsSerializable {
@Override
public long getId() {
return 0;
}
}
import com.google.gwt.user.client.rpc.IsSerializable;
public class FooBase implements IsSerializable{
...
}
public class Foo extends FooBase{
...
}
客戶:
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.gwt.test.shared.FooBase;
import com.gwt.test.shared.GetItemRequest;
@RemoteServiceRelativePath("get")
public interface GetService extends RemoteService {
public <T extends FooBase> T get(GetItemRequest<T> request);
}
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwt.test.shared.FooBase;
import com.gwt.test.shared.GetItemRequest;
public interface GetServiceAsync {
void get(GetItemRequest request, AsyncCallback<FooBase> callback);
}
public void onModuleLoad() {
GetServiceAsync getService = GWT.create(GetService.class);
getService.get(new GetFooRequest(), new AsyncCallback<FooBase>() {
@Override
public void onFailure(Throwable caught) {
System.out.println("failure");
}
@Override
public void onSuccess(FooBase result) {
System.out.println("success");
}
});
...
}
服務器:
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.gwt.test.client.GetService;
import com.gwt.test.shared.Foo;
import com.gwt.test.shared.FooBase;
import com.gwt.test.shared.GetItemRequest;
public class GetServiceImpl<T extends FooBase> extends RemoteServiceServlet implements GetService {
@Override
public <T extends FooBase> T get(GetItemRequest<T> request) {
...
}
}
網絡。XML:
<servlet>
<servlet-name>getServlet</servlet-name>
<servlet-class>com.x.y.z.server.GetServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getServlet</servlet-name>
<url-pattern>/context_root/get</url-pattern>
</servlet-mapping>
您的意思是'GetItemRequest'? –
@PaulBellora是的,很好。這是一個錯字,在真正的代碼中它是'T extends FooBase' –