DefaultHandlerExceptionResolver:已解决[org.springframework.web.HttpMediaTypeNotSupportedException:内容类型“文本/纯文本”不受支持]

时间:2020-05-09 21:34:18

标签: angular spring typescript spring-boot

我尝试将数据发送到Java后端,这是我的代码。 我的Java控制器:

@RequestMapping(value = "/saveExperience", method = RequestMethod.POST, consumes =MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Experience> save(@RequestBody @Valid Experience experience,@RequestParam(value = "userId") String id, Errors errors ) {

            if (errors.hasErrors()) {
                return new ResponseEntity(new MethodArgumentNotValidExceptionHandler(), HttpStatus.BAD_REQUEST);
            }
            Experience newExperience= new Experience();
            newExperience.setUser(userMetierImpl.findUser(Long.parseLong(id)));
            newExperience.setCompany(experience.getCompany());
            newExperience.setTitle(experience.getTitle());
            newExperience.setSummary(experience.getSummary());
            newExperience.setStartDate(experience.getStartDate());
            newExperience.setEndDate(experience.getEndDate());
            newExperience.setWorkInThere(experience.isWorkInThere());
            experienceRepository.save(newExperience);
            return new ResponseEntity<>(HttpStatus.OK);
}     

我的TS组件

saveExperience() {

   this.profileService.saveExperience(this.experience,this.currentUser.id)
    .subscribe(data => console.log(data), error => console.log(error));
}

我的TS服务:

      saveExperience(experience: Object,userId: string): Observable<Object> {

    const newRequest = new HttpRequest('POST', API_URL + 'saveExperience/',JSON.stringify({userId,experience}));
      return this.https.request(newRequest);
  }

0 个答案:

没有答案