我有以下设置:
我的控制器:
@RequestMapping("/project")
@RestController
public class ProjectController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
ProjectService projectService;
@CrossOrigin
@PostMapping(value = "/createProject")
public ResponseEntity createProject(@RequestBody ProjectDto projectJsonString) {
return ResponseEntity.ok(HttpStatus.OK);
}
}
在我的
.service.ts
以下内容:
this.http.post('http://localhost:8080/project/createProject', JSON.stringify(project)).
subscribe( (res) => {
this.logger.info('Response: ' + res);
});
我的DTO:
public class ProjectDto {
private String projectName;
private String projectNumber;
private String projectArea;
private String managerName;
private String managerShorthand;
}
但是,当我将应用程序构建到jar文件并执行它时,在执行api调用时会出现以下错误:
HttpErrorResponse {headers: HttpHeaders, status: 415, statusText: "OK", url: "http://localhost:8080/project/createProject", ok: false, â¦}
error:
error: "Unsupported Media Type"
message: "Content type 'text/plain;charset=UTF-8' not supported"
path: "/project/createProject"
status: 415
timestamp: "2018-12-10T21:41:26.036+0000"
当我
curl
它。有人能告诉我我做错了什么吗?