【发布时间】:2020-10-01 03:13:35
【问题描述】:
在我下面的代码中,请求持有数据{widgetName: "widgetName", widgetCriteria: "Activities", followUpDate: "1591727400000", uid: "someId"}
let request = JSON.parse(JSON.stringify(Object.assign(this.registrationForm.value, ...req)));
delete request.widgetFIlterOptions;
let uid = JSON.parse(window.localStorage.getItem("user")).uid;
request.uid = uid;
this.openWindow = false;
console.info("request-->", request);
this.contactService.addWidget(request).subscribe(res=> {
this.emService.updateWidgits();
})
在 addWidget() 函数/方法中,我们调用 post 请求。 但是在调用发布请求后,ResetController 类应该收到带有其他数据的“followUpDate”。但是在我的情况下,“followUpDate”缺失,但我可以看到其他数据。
任何人都可以在这件事上提供帮助吗?我在这里缺少什么?我是 Angular 的新手。
addWidget(widget, data?) {
console.info("widget-->", widget); // here followUpDate is present
this.http.post(this.api.createWidget, widget).pipe(map(data => {
console.info("data-->", data); // this does not have the followUpDate.
let message = "Widget created successfully";
data['data'] = this.filterWidgets(data).length > 0 ? this.filterWidgets(data): alert("No data Available");
this.widgets.unshift(data);
this.toastr.success(message);
}),catchError(err => {
this.toastr.error(err.error);
return throwError(err);
}));
下面是我的休息控制器类
@RestController
public class DashboardController {
@Autowired
Service service;
@PostMapping(path = "createcriteria", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "create the deal", response = Dashboard1.class)
public Dashboard1 saveCriteria(@RequestBody Dashboard1 dashboard1) {
System.out.println(dashboard1); // here "followUpDate" is missing
return service.saveCriteria(dashboard1);
}
}
下面是我的 Dashboard1 类
@Document(collection = "Dashboard1")
@JsonInclude(Include.NON_NULL)
public class Dashboard1 {
@Id
@ApiModelProperty(notes = "The database generated product ID")
private String id;
@Field(value = "widgetname")
private String WidgetName = null;
@Field(value = "widgetcriteria")
private String WidgetCriteria = null;
@Field(value = "uid")
private String uid = null;
@Field(value = "activitytype")
private String activityType = null;
@Field(value = "contactname")
private String contactName = null;
@Field(value = "updateby")
private String updateBy = null;
@Field(value = "followUpDate")
private String followUpDate = null;
// below all the getters, setters and toString() methods present
}
【问题讨论】:
-
好吧,我们至少可以调试问题发生的位置,我希望它与反序列化有关。如果您通过 Postman 将与您在问题中发布的完全相同的 json 发送到 Java 后端,会发生什么情况?里面有
followUpDate吗? -
@IvarReukers 抱歉回复晚了...今天从邮递员那里尝试过,但仍然没有在服务器中获得“followUpDate”。
标签: json angular typescript spring-boot rest