MainActivity类
参考集合传值 :
https://blog.csdn.net/hhoo3344521/article/details/80075409
https://blog.csdn.net/qq_36342492/article/details/90691559
public class MainActivity extends AppCompatActivity {
private static final String BASE_URL = "http://192.168.1.210:8880";
@BindView(R.id.buton_bu)
Button butonBu;
@BindView(R.id.text_tv)
TextView textTv;
private NetApi api;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.build();
api = retrofit.create(NetApi.class);
reqApi();
}
public void reqApi() {
//添加Data_text数据到服务器
api.saveUser(new User("Data_text")).enqueue(new Callback<User>() {
//添加成功,已经到后台了
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.i("onResponse","Log="+response.body().getName());
}
@Override
public void onFailure(Call<User> call, Throwable t) {
}
});
}
}
NetApi类
public interface NetApi {
@POST("/file/upload")
Call<User> saveUser(@Body User user);
}
User类
public class User {
public User(){
}
public User(String name) {
this.name = name;
}
public String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}