首页 > 解决方案 > 邮递员获取呼叫 500 内部服务器错误

问题描述

这个 GET 端点在这里遇到了一些问题。出于某种原因,调用状态 500 Internal Server Error 并且正文为空。

这是带有 GET 调用的代码:

@GetMapping
public List<TitulosPagar> getTitulosPagar() {

    System.out.println("GET called");
    List<TitulosPagar> titulos = titulosPagarService.pesquisar();
    System.out.println(titulos);

    return titulos;

titulosPagarService.pesquisar() 返回一个 JpaRepository.findAll() 以及完整的 titulosPagar 列表。

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 Internal Server Error

邮递员回应

邮递员控制台响应:

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);
}

我将 localServer 与 PostgreSQL 一起使用。

它不t seem to be a problem in the code. But I don知道,你明白什么是错的吗?

标签: javascriptjavapostgresqlpostmanrestful-authentication

解决方案


我知道了!问题在于,当获取要在邮递员中显示的属性时,它进入了引用其他对象的对象的循环。为了解决这个问题,我必须消除重复出现的 Get(),或者只是从对象中获取 id


推荐阅读