【发布时间】:2015-11-18 10:03:14
【问题描述】:
我的javascript 中有一个AJAX 呼叫 -
var obj = {
CAEVCode:"TEST2",
CAEVName:"TriggerRedemption",
DateofReceipt:"YAHOO",
LogReference:"test1"
}
var obj1=JSON.stringify(obj);
$.ajax({
url:'./webapi/input/post',
type: 'POST',
data:obj1,
contentType : "application/json",
dataType:'json',
success:function(data)
{
var values = JSON.stringify(data);
alert(values);
},
error:function(xhr,textstatus,errorthrown){
alert(xhr.responseText);
alert(textstatus);
alert(errorthrown);
}
},'json');
当JavaScript 被调用并且AJAX 调用被调用时,我的对象使用RESTFul Web Services 被发送到(POST) 到下面的URL -> ./webapi/input/post,对应的InputResponse 我拥有的类是如下 -
@Path("/input")
public class InputResponse {
SimpleDateFormat dt = new SimpleDateFormat("dd-MM-yyyy");
InputService inputservice = new InputService();
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Input postInputRecord(Input obj) throws SQLException, ParseException{
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
System.out.println(gson.toJson(obj));
String CAEVCode=obj.getCAEVCode();
String CAEVName=obj.getCAEVName();
String DateOfReceipt =obj.getDateofReceipt();
String LogReference=obj.getLogReference();
addUser(new Input(LogReference,CAEVCode,CAEVName,DateOfReceipt));
return obj;
}
public Input addUser(Input input) throws SQLException{
return inputservice.addUsers(input);
}
接下来,我的POJO如下——
@XmlRootElement
public class Input {
private String CAEVCode;
private String CAEVName;
private String DateofReceipt;
private String LogReference;
public Input() { }
public Input(String logReference, String cAEVCode, String cAEVName,
String dateofReceipt ) {
super();
LogReference = logReference;
CAEVCode = cAEVCode;
CAEVName = cAEVName;
DateofReceipt = dateofReceipt;
}
public String getLogReference() {
return LogReference;
}public void setLogReference(String logReference) {
LogReference = logReference;
}public String getCAEVCode() {
return CAEVCode;
}public void setCAEVCode(String cAEVCode) {
CAEVCode = cAEVCode;
}public String getCAEVName() {
return CAEVName;
}public void setCAEVName(String cAEVName) {
CAEVName = cAEVName;
}public String getDateofReceipt() {
return DateofReceipt;
}public void setDateofReceipt(String dateofReceipt) {
DateofReceipt = dateofReceipt;
}
}
问题是,当我运行我的页面时,JavasScript 对象在AJAX 调用InputResponse 类的帮助下成功发送,但并非所有值都出现了。 2个值是空的,另一个是正确的。我整个早上都在尝试调试它,但没有帮助。我还有另一段代码用于类似的业务逻辑,它恰好工作得很好。我也碰巧尝试过其他形式的AJAX 调用来与之相处,但我仍然是徒劳的。非常感谢任何帮助。
【问题讨论】:
标签: java ajax rest pojo restful-url