我试图像这样创建简单的服务
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import com.dolphithronelab.siastar.response.AuthResponse;
public interface SIAStarService {
@POST("auth");
@FormUrlEncoded;
Call<AuthResponse>login(@Field("username") String username, @Field("password") String password);
}
但我的Android工作室显示错误说:@POST不适用于类型,如何处理? 这是我的AuthResponse课程 import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName;
public class AuthResponse {
@SerializedName("login")
@Expose
private Boolean login;
@SerializedName("user")
@Expose
private User user;
@SerializedName("pesan")
@Expose
private String pesan;
@SerializedName("token")
@Expose
private String token;
public Boolean getLogin() {
return login;
}
public void setLogin(Boolean login) {
this.login = login;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getPesan() {
return pesan;
}
public void setPesan(String pesan) {
this.pesan = pesan;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
答案 0 :(得分:6)
在注释后删除分号
public interface SIAStarService {
@POST("auth")
@FormUrlEncoded
Call<AuthResponse>login(@Field("username") String username, @Field("password") String password);
}