【发布时间】:2016-06-02 05:59:57
【问题描述】:
我正在尝试使用 Volley 框架的 Post 方法将自定义对象发送到服务器端。我知道 getBody 方法应该被重载。但是要指定为正文内容类型的内容是什么? getBody() 和 getBodyContentType() 方法的代码将节省我的时间。
这是我的模型类:
package ar.sample.model;
import java.sql.Timestamp;
public class Location {
private Integer id;
private String locationName;
private Double latitude;
private Double longitude;
private Float radius;
private String logicalGroup;
private String parentLocation;
private String country;
private String city;
private String type;
private String description;
private Integer status;
private Timestamp createdTime;
private Timestamp updatedTime;
private String createdByUser;
private String updatedByUser;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public Float getRadius() {
return radius;
}
public void setRadius(Float radius) {
this.radius = radius;
}
public String getLogicalGroup() {
return logicalGroup;
}
public void setLogicalGroup(String logicalGroup) {
this.logicalGroup = logicalGroup;
}
public String getParentLocation() {
return parentLocation;
}
public void setParentLocation(String parentLocation) {
this.parentLocation = parentLocation;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Timestamp getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Timestamp createdTime) {
this.createdTime = createdTime;
}
public Timestamp getUpdatedTime() {
return updatedTime;
}
public void setUpdatedTime(Timestamp updatedTime) {
this.updatedTime = updatedTime;
}
public String getCreatedByUser() {
return createdByUser;
}
public void setCreatedByUser(String createdByUser) {
this.createdByUser = createdByUser;
}
public String getUpdatedByUser() {
return updatedByUser;
}
public void setUpdatedByUser(String updatedByUser) {
this.updatedByUser = updatedByUser;
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("locationName", locationName)
.add("latitude", latitude)
.add("longitude", longitude)
.add("radius", radius)
.add("logicalGroup", logicalGroup)
.add("parentLocation", parentLocation)
.add("country", country)
.add("city", city)
.add("type", type)
.add("description", description)
.add("status", status)
.add("createdTime", createdTime)
.add("updatedTime", updatedTime)
.add("createdByUser", createdByUser)
.add("updatedByUser", updatedByUser)
.toString();
}
}
我在服务器端的代码是:
@RequestMapping(value = "/location", method = RequestMethod.POST)
public Location createLocationComplete(@RequestBody @Valid Location location) {
LOGGER.debug("API: Create {}", location);
//location = composeLocation(location);
return locationService.insert(location);
}
如何使用 Volley 框架通过 POST 方法发送位置对象?
【问题讨论】:
-
您想使用 volley 从 android 向服务器发送值吗?
-
@YounasBangash:是的。
-
你想在 php 中接收那些参数?
-
@YounasBangash:Nope.its Spring boot。