javascript - Postman Get call 500 内部服务器错误

标签 javascript java postgresql postman restful-authentication

此 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 response

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/

相关文章:

java - ORA-00979 不是带有 case 的 group by 表达式

java - 如何实现线程安全的收集器?

node.js - 我无法在环回 ORM 模型中设置唯一字段

javascript - swfObject + scriptaculous Autocompleter = 失败

javascript - 如何将此 JSON 从 PHP 转换为 Javascript 数组

java - 无法从 EMR 中运行的 Spark 应用程序删除 AWS SQS 消息

sql - 使用 ecto 预加载所有链接记录

XP下的PostgreSQL认证

javascript - 两个递归函数之间的区别

javascript - 当前 URL hashchange 事件将新哈希附加到目标 URL 并链接到它