在我的后端发送null变量,我在前端做得不对吗

  • 本文关键字:前端 变量 后端 null java spring
  • 更新时间 :
  • 英文 :


我正试图将一个变量从我的角度前端发送到我的sprinboot后端。但是变量的值正在变为null。我尝试了几种方法,但都不起作用。

我做错什么了吗?

Springboot JAVA

@RequestMapping(value = "/api/product")
@RequestMapping(value = "v2/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity <Page<ComponentDTO>> search(Long id, Pageable pageable) throws Exception {
return new ResponseEntity<>(this.service.search(id, pageable), HttpStatus.OK);
}

服务Typescript

PATH = '/server/api/product';
list(id: number): Observable<EntityBase<Component>> {
return this.httpClient.get<EntityBase<Component>>(`${this.PATH}/v2/${id}`);
}

跟踪

ORA-00932:不一致的数据类型:预期的NUMBER得到二进制

尝试更改这个:

@RequestMapping(value = "v2/{id}",

请给这个:

@RequestMapping(value = "/v2/{id}",

在v2 之前添加

您的代码中有很多不正确的地方:

  1. 在端点值中添加反斜杠
  2. 将@PathVariable注释添加到ID字段中
  3. 您使用分页错误

没有分页的Bellow示例,如果您想添加分页,请尝试在URL中发送页码作为查询参数,并使用@RequestParam注释来实现这一点。

@RequestMapping(value = "/v2/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity <Page<ComponentDTO>> search(@PathVariable("id") Long id) throws Exception {

提示:改为使用@GetMapping。

最新更新