【发布时间】:2021-11-22 18:37:49
【问题描述】:
我对通过 post 方法的 http 请求有疑问。 然后发送到具有映射为端点的后端
我的汽车控制器
@RequestMapping(value = "/car")
@AllArgsConstructor
@CrossOrigin
public class CarController {
@PostMapping(value = "/test/{code}")
public ResponseEntity<String> getCars(@PathVariable(required = true) String code) throws URISyntaxException {
return ResponseEntity.ok("Response OK");
}
}
我的环境
export const environment = {
production: false,
apiEndpoint: "http://localhost:8080/my-app/"
};
我的 app.service.component.ts
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
getCars() {
const url = `${environment.apiEndpoint}`+ "/car/teste/?" + `${code}`;
this.http.get<any>(url).subscribe(resp => {
console.log(resp)
});
}
错误日志
请求出现 404 错误并显示以下消息
错误{正文:{…},网址:'http://localhost:8080/car/test/',标题: HttpHeaders,状态:404,状态文本:'未找到'}正文:{错误: “找不到集合'汽车'”}标头:HttpHeaders {normalizedNames: 地图(0),lazyUpdate:空,lazyInit:ƒ}状态:404statusText:“不是 找到"url:"http://localhost:8080/my-app/car/test"[[Prototype]]: 对象
【问题讨论】:
标签: angular spring-boot