此 GET 端点遇到一些问题。由于某种原因正在调用状态 500 内部服务器错误并且正文为空。
这是带有 GET 调用的代码:
@GetMapping
public List<TitulosPagar> getTitulosPagar() {
System.out.println("GET called");
List<TitulosPagar> titulos = titulosPagarService.pesquisar();
System.out.println(titulos);
return titulos;
titulosPagarService.pesquisar() 返回一个包含 titulosPagar 完整列表的 JpaRepository.findAll()。
sysoutPrint 显示它获取了由对象 TitulosPagar 生成的列表:
GET called
[br.com.lev.ficpagar.model.TitulosPagar@13d10944, br.com.lev.ficpagar.model.TitulosPagar@5a57aa65,
br.com.lev.ficpagar.model.TitulosPagar@1ac0f72, br.com.lev.ficpagar.model.TitulosPagar@3a052abc]
但是在 Postman 中我得到了一个空正文和 500 内部服务器错误
postman 控制台响应:
GET /ficpagar/titulospagar HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: b273167d-92d4-44e6-bea0-88c8b70af99e
Host: localhost:8080
Accept-Encoding: gzip, deflate, be
Connection: keep-alive
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Allow-Credentials: true
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 14 Apr 2020 20:31:03 GMT
Connection: close
,
curl --location --request GET 'localhost:8080/ficpagar/titulospagar' \
--header 'Content-Type: application/json' \
--data-raw ''
奇怪的是这个测试 GET 端点工作正常。
@GetMapping
public String test() {
return "Everything fine!";
}
以及 POST 端点:
@PostMapping
public ResponseEntity<TitulosPagar> criar(@Valid @RequestBody TitulosPagar tituloPagar, HttpServletResponse response) {
tituloPagar = titulosPagarService.criar(tituloPagar);
URI uri = ServletUriComponentsBuilder.fromCurrentRequestUri().path("/{codigo}").buildAndExpand(tituloPagar.getId()).toUri();
response.setHeader("Location", uri.toASCIIString());
return ResponseEntity.created(uri).body(tituloPagar);
}
我使用带有 PostgreSQL 的本地服务器。
它没有 t seem to be a problem in the code. But I don
不知道,你知道可能出了什么问题吗?
最佳答案
我明白了! 问题是,当获取要在 postman 中显示的属性时,它进入了引用其他对象的对象的循环。 为了解决这个问题,我必须消除重复出现的 Get(),或者只是从对象中获取 id
关于javascript - Postman Get call 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61217098/