邮递员获取呼叫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()返回带有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]

但是在邮递员中,我得到了一个空的正文和500个内部服务器错误

Postman response

邮递员控制台响应:

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中使用localServer。

t seem to be a problem in the code. But I don不知道,您知道这可能是错吗?

tian_tang123 回答:邮递员获取呼叫500内部服务器错误

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

本文链接:https://www.f2er.com/2441609.html

大家都在问