Missing URI template variable 'usuarioEntidade' for method parameter of type Long

15,743

Solution 1

Your problem is that the name of the path variable in your rest request does not match the name of the variable passed to your java method.

You have two options:

@RequestMapping(method = RequestMethod.GET, value = "/distrito/{idEntidade}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Distritos>> buscarTodosDistritos(@PathVariable("idEntidade") Long usuarioEntidade)

Or:

@RequestMapping(method = RequestMethod.GET, value = "/distrito/{usuarioEntidade}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Distritos>> buscarTodosDistritos(@PathVariable Long usuarioEntidade)

Solution 2

You have to make changed in buscarTodosDistritos() method as below

@PathVariable(value="idEntidade") Long usuarioEntidade  <--- add value in path variable

or

@PathVariable Long idEntidade   <--- or change variable name to map same as the one in the url
Share:
15,743

Related videos on Youtube

Eduardo Krakhecke
Author by

Eduardo Krakhecke

Iniciante na programação Java e Android.

Updated on September 16, 2022

Comments

  • Eduardo Krakhecke
    Eduardo Krakhecke over 1 year

    I try to pass a param in this method here

    @RequestMapping(method = RequestMethod.GET, value = "/distrito/{idEntidade}", produces = MediaType.APPLICATION_JSON_VALUE)
        public ResponseEntity<Collection<Distritos>> buscarTodosDistritos(@PathVariable Long usuarioEntidade) throws ServletException { 
    
            Collection<Distritos> distritosBuscados = distritosService.buscarFiltro(usuarioEntidade);//parametro, que é o id_entidade, para passar na query de busca distritos
                return new ResponseEntity<>(distritosBuscados, HttpStatus.OK);
        } 
    

    and i got this error

    Missing URI template variable 'usuarioEntidade' for method parameter of type Long 
    

    I'm calling this request on my front end right here

     idEntidade = Number(localStorage.getItem("idEntidade"));
    
    
    
    $http({
            method : 'GET',
            url : '/user/distrito/' +idEntidade         
        }).then(function(response) {
            $scope.distritos = response.data;
    
        }, function(response) {
            console.log(response.data);
            console.log(response.status);
        });
    }; 
    

    then got an error..

    Missing URI template variable 'usuarioEntidade' for method parameter of type Long