英文:
Java Spring how to getmapping with name
问题
如何使得 @getmapping 不带有 id,而是通过(String)名称进行匹配......
@GetMapping("/employees/{id}")
Employee one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new EmployeeNotFoundException(id));
}
英文:
how can I make @getmapping without id and by (String) name .....
@GetMapping("/employees/{id}")
Employee one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new EmployeeNotFoundException(id));
}
答案1
得分: 0
你可以以与目前相同的方式进行,只需将 id 替换为 name
@GetMapping("/employees/{name}")
Employee one(@PathVariable String name) {
...
}
英文:
You can do it the same way you already are but switch out id with name
@GetMapping("/employees/{name}")
Employee one(@PathVariable String name) {
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论