javascript - 邮递员获取呼叫 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
知道,你明白什么是错的吗?
解决方案
我知道了!问题在于,当获取要在邮递员中显示的属性时,它进入了引用其他对象的对象的循环。为了解决这个问题,我必须消除重复出现的 Get(),或者只是从对象中获取 id
推荐阅读
- powershell - 为每个文件创建文件夹并将文件移动到文件夹中
- javascript - Html 视频支持不同的视频 src 类型
- git - 每当我提交时,它都会链接到我的另一个 github 帐户的用户名
- selenium - Selenium 测试因最近将 safari 更新到版本 13 而中断?
- spring - Spring 方法级别安全性获取 null 属性 EL1007E:在 null 上找不到属性或字段“价格”
- php - 我想删除重复的``````如果它们是连续的但我的条件“if($value ===”“)”不起作用
- excel - 基于单元格的 VBA 条件格式 .rank 值 - Top10
- webhooks - DialogFlow 文件上传到服务器
- javascript - 数组是否未定义,因为组件在加载数据之前正在渲染?
- ios - iOS 13 如何在导航栏中隐藏 UISearchController 搜索栏