I have this situation in Angular . I want to pass some parameter for a SQL query to spring.
This is the variable in angular i want to pass in Spring
var medicoRicercato = {
nome: $scope.medico.nome,
cognome: $scope.medico.cognome,
codiceFiscale: $scope.medico.codiceFiscale,
codiceSpecialita: $scope.specialitaSelezionata.codice,
codicePrestazione: $scope.prestazione.codice
};
This is the http.get request i try to do
$http({
url: 'http://localhost:8080/ProgettoClinicaAngular/getMedici/',
method: "GET",
params:medicoRicercato
}).then(
function successCallback(response) {
},
function errorCallback(response) {
}
);
And this is my Spring controller
@RequestMapping(value="/getMedici", method=RequestMethod.GET)
public MedicoView authenticateUser(@RequestBody MedicoView medico) {
return medico;
}
i try to do so much solution i read on internet , but i not find one work for me , all solution have a problem. I try also with @PathVariable in spring controller , but from angular how i struct a string to pass ? i can pass this like a simple string with space for difference the parameter i want to pass? i cant pass this like a JSON?
Then , can anyone tell me :
Wich is the best way for pass parameter in HTTP GET from angular to Spring?
SOLUTION
With help of all i found a solution.
This is my angular code for pass parameter
var medicoRicercato = {
nome: $scope.medico.nome,
cognome: $scope.medico.cognome,
codiceFiscale: $scope.medico.codiceFiscale,
codiceSpecialita: $scope.specialitaSelezionata.codice,
codicePrestazione: $scope.prestazione.codice
};
$http.get('http://localhost:8080/ProgettoClinicaAngular/getMedici/',{params:
medicoRicercato}).then(
function successCallback(response) {},
function errorCallback(response) {}
);
This is my Spring controller
@RequestMapping(value ="/getMedici")
public List<Medico> getUsersForGrid( @RequestParam(value = "nome",required=false) String nome, @RequestParam(value = "cognome",required=false ) String cognome, @RequestParam(value = "codiceFiscale", required=false) String codiceFiscale, @RequestParam(value = "codiceSpecialita", required=false) Integer codiceSpecialita, @RequestParam(value = "codicePrestazione", required=false) Integer codicePrestazione)
{
List<Medico> listaMedici=null;
listaMedici=medicoBuisiness.getMediciWithQuery(nome, cognome, codiceFiscale, codiceSpecialita, codicePrestazione);
return listaMedici;
}