Tag: 微服务

响应状态HTTP SpringBoot Kotlin Api

我从kotlin开始,如果任何人都可以帮助我,我已经有一个关于如何返回http状态的问题,当我的真正的,如果它返回200好,当它的任何其他方式,返回404 NotFound。 我试着按照下面的代码来做,但是在所有情况下,它只返回状态200 OK @DeleteMapping("{id}") fun delete(@PathVariable id: Long): ResponseEntity<Unit> { try { if (dogRepository.exists(id)) { dogRepository.delete(id) } return ResponseEntity.ok().build() } catch (e: Exception) { return ResponseEntity.notFound().build() } }