【问题标题】:How to return boolean value in ResponseEntity?如何在 ResponseEntity 中返回布尔值?
【发布时间】:2019-12-17 09:44:37
【问题描述】:

控制器代码如下:

@PutMapping("/update-student")
public ResponseEntity<Student>updateStudent(@RequestBody Student student)throws Exception{
  boolean getStudent = studentService.updateStudent(student);
  return new ResponseEntity<Student>(getStudent,HttpStatus.OK);
}

【问题讨论】:

  • 返回布尔值的用例是什么?如果你想在学生的保存/更新失败的情况下返回false,你最好返回一个错误代码。

标签: java spring-boot controller repository


【解决方案1】:

您正在返回 ResponseEntity 类型的 Student (ResponseEntity&lt;Student&gt;)

要返回 Boolen,您必须执行类似的操作 ResponseEntity&lt;Boolean&gt;.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2013-03-28
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 2015-02-14
    • 2015-04-07
    相关资源
    最近更新 更多