这是我的后台代码:
@PostMapping("/certifications")
@Timed
public ResponseEntity<Certification> createCertification(@RequestBody Certification certification) throws URISyntaxException {
log.debug("REST request to save Certification : {}", certification);
if (certification.getId() != null) {
throw new BadRequestAlertException("A new certification cannot already have an ID", ENTITY_NAME, "idexists");
}
log.info("certification的id {}", certification.getId());
Certification result = certificationRepository.save(certification);
log.info("save 后的certifications {}", result.getId());
System.out.println("/api/certifications/" + result.getId());
System.out.println(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()));
return ResponseEntity.created(new URI("/api/certifications/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result);
}
这是我前端代码:
this.certification.type = '身份证';
this.certification.isverify = '未审核';
this.certification.userId = this.user.id;
console.log("进入examine()");
console.log(this.certification);
this.isSaving = true;
if (this.certification.id !== undefined) {
this.subscribeToSaveResponse(
this.certificationProvider.update(this.certification));
} else {
this.subscribeToSaveResponse(
this.certificationProvider.create(this.certification));
}
console.log("实名认证完成");
create(certification: Certification): Observable<Certification> {
const copy = this.convert(certification);
return this.http.post(this.resourceUrl, copy).map((res: Response) => {
console.log("Response 的"+res.json());
const jsonResponse = res.json();
console.log("jsonResponse 的"+jsonResponse);
return this.convertItemFromServer(jsonResponse);
});
}
private subscribeToSaveResponse(result: Observable<Certification>) {
//noinspection TypeScriptUnresolvedVariable
console.log("subscribeToSaveResponse 里的 result"+result);
result.subscribe((res: Certification) =>
this.onSaveSuccess(res), (res: Response) => this.onSaveError());
}
private onSaveSuccess(result: Certification) {
this.event.publish('carListModification', 'OK');
this.isSaving = false;
this.view.dismiss(result);
}
private onSaveError() {
this.isSaving = false;
console.log("失败");
}