我正在學習改造。我已經完成了創建一個類login
使用改造(通過以下教程在互聯網上)。改造:使用改造將數據發送到服務器
現在,我嘗試創建其他進程sign up
。我很困惑哪一個我應該在login
函數中改變。說實話,我無法理解這些概念。
這個我幾個login
的代碼:
UserLogin.java
public class UserLog {
private String id;
private String username;
private String password;
//getter and setter...
RestCallBack.java
public abstract class RestCallBack<T> implements Callback<T> {
public abstract void failure(RestError restError);
@Override
public void failure (RetrofitError error){
RestError restError = (RestError) error.getBodyAs(RestError.class);// create your own class as
// how the error message gonna showup from server side if there is an error
if(restError != null){
failure(restError);
}else{
failure(new RestError(error.getMessage()));
}
}
}
RestError.java
public class RestError {
public Integer errorCode;
public String extendedMessage;
private String message;
private String moreInfo;
private Integer status;
//getter and setter
SessionRequest.j AVA
public class SessionRequestInterceptor implements RequestInterceptor {
private static final String TAG = SessionRequestInterceptor.class.getSimpleName();
@Override
public void intercept(RequestFacade request) {
request.addHeader("Content-Type", "application/json");/*
you can add header here if you need in your api
*/
}
}
RestLoginCLient.java
public class RestClient_Login {
private static RestApi_login REST_CLIENT;
private static String ROOT = "http://192.168.10/testapp";
static {
setUpRestClient();
}
public static RestApi_login get()
{return REST_CLIENT;}
private static void setUpRestClient(){
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint(ROOT)
.setClient(new OkClient(new OkHttpClient()))
.setRequestInterceptor(new SessionRequestInterceptor())
.build();
REST_CLIENT = restAdapter.create(RestApi_login.class);
}
RestApi.java
public interface RestApi_login {
@POST("/user/login")
void login(@Body UserLog user,
RestCallBack<LoginResponse> callBack);
}
LoginResponse.java
public class LoginResponse {
public String email;
public String id;
public String error;
public UserLog resp;
LoginResponse(){}
//getter and setter
指導我哪一個代碼,我應該在鄰改變rder我可以創建我的sign up
過程
'註冊'上面哪個代碼應該改變? –