任何帮助都将在这一点上受到赞赏我觉得我错过了一些但我无法弄清楚
@RequestMapping(value = "/addquery", method = RequestMethod.POST,headers = "Accept=application/json")
public @ResponseBody String recordEnquiry(@ModelAttribute(value = "enquiry") Enquiry enquiry)
{
//agentDAO.addEnquiry(enquiry);
log.debug("Received request to add new query");
String message = "Error posting the ordered details. Please contact admin";
System.out.println("bsname========"+ enquiry.getBusinessName());
System.out.println("subject========"+enquiry.getSubject());
System.out.println("query========"+enquiry.getQuery());
System.out.println("agent========"+enquiry.getAgent());
System.out.println("date========"+enquiry.getDate());
System.out.println("latitude========"+enquiry.getLatitude());
System.out.println("longitude========"+enquiry.getLongitude());
agentDAO.addQuery(
enquiry.getBusinessName(),
enquiry.getSubject(),
enquiry.getQuery(),
enquiry.getAgent(),
enquiry.getDate(),
enquiry.getLatitude(),
enquiry.getLongitude());
message = "Enquiry Added Successful";
return message;
}
从发送应用程序发布时
public class HttpPostTask<T> extends AsyncTask<MediaType, Void, String> {
private final HttpJsonPostTaskCaller caller;
private final T objectToPost;
private final String uri;
private final int requestCode;
boolean errorOccured;
public HttpPostTask(HttpJsonPostTaskCaller caller, T objectToBePosted,
String uri, int requestCode) {
super();
this.caller = caller;
this.objectToPost = objectToBePosted;
this.uri = uri;
this.requestCode = requestCode;
}
@Override
protected void onPreExecute()
{
caller.showLoadingProgressDialog ();
}
@Override
protected String doInBackground(MediaType... params) {
try {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Content-Type", MediaType.APPLICATION_JSON.toString());
requestHeaders.add("Accept", MediaType.APPLICATION_JSON.toString());
requestHeaders.setAcceptEncoding(ContentCodingType.GZIP);
HttpEntity<?> requestEntity = new HttpEntity<Object>(objectToPost,requestHeaders);
RestTemplate restTemplate = new RestTemplate ();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter ());
restTemplate.getMessageConverters().add(new FormHttpMessageConverter ());
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter ());
restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter ());
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter ());
restTemplate.getMessageConverters().add(new SourceHttpMessageConverter());
System.out.println ("objectToPost <=========>"+objectToPost.toString ());
System.out.println ("objectToPost <=========>"+objectToPost);
ResponseEntity<?> response = restTemplate.exchange(uri, HttpMethod.POST, requestEntity,String.class,objectToPost);
System.out.println ("response <========----=>"+response);
return response.getBody().toString();
}
catch (Exception e)
{
errorOccured = true;
System.out.println ("Post Task Exception <=========>"+e);
caller.onAsyncTaskFailed(getClass(), requestCode, e);
return null;
}
}
来自应用活动的
protected void saveData(Enquiry enquiry) {
String uri = getString(R.string.baseURI) + "addquery";
new HttpPostTask<Enquiry> (Add_EnquiryActivity.this, enquiry,uri, 0).execute ();
System.out.println("bsname========"+ enquiry.getBusinessName());
System.out.println("subject========"+enquiry.getSubject());
System.out.println("query========"+enquiry.getQuery());
System.out.println("agent========"+enquiry.getAgent());
System.out.println("date========"+enquiry.getDate());
System.out.println("latitude========"+enquiry.getLatitude());
System.out.println("longitude========"+enquiry.getLongitude());
}
来自应用程序的日志
I/System.out: bsname========brisk sln
I/System.out: subject========test
I/System.out: query========test
I/System.out: agent========8
I/System.out: date========07-12-2016
I/System.out: latitude========-1.2979896
I/System.out: longitude========36.7651589
I/System.out: objectToPost <=========>com.bsl.salesapp.utils.Enquiry@749a070
来自网络服务
bsname========null
subject========null
query========null
agent========null
date========null
latitude========null
longitude========null
可能是什么问题? 感谢