弹簧靴返回未找到

时间:2021-06-07 17:14:25

标签: java spring-boot spring-mvc

我需要创建一个rest方法来通过postman中的id获取客户端,我什至创建了该方法,但是它没有通过spring boot通过id返回任何信息。

ClientControle.java:

@GetMapping(value = "/clientes/{id}")
public Cliente listCliente(@PathVariable("id") long id){
    return clienteService.getById(id);

客户服务:

public interface ClienteService {
    
    Cliente getById(long id);
    
    List<Cliente> getAll();
    
    Cliente save(Cliente cliente);

}

但我有以下错误:

enter image description here

2 个答案:

答案 0 :(得分:1)

您在控制器(类)级别拥有 @RequestMapping("clientes"), 所以你的实际 URL 应该是 http://localhost:8080/clientes/clientes/1

答案 1 :(得分:1)

enter image description here

根据图片中的代码,您分享了您在班级级别也有 clientes
或者您可以从此处删除,然后 localhost:8080/clientes/1 将起作用
或者您需要使用 localhost:8080/clientes/clientes/1