Skip to content

Instantly share code, notes, and snippets.

@lucaspmarra
Created January 4, 2023 17:00
Show Gist options
  • Select an option

  • Save lucaspmarra/db1cb2b667c4b5c97230f7e8d805b25d to your computer and use it in GitHub Desktop.

Select an option

Save lucaspmarra/db1cb2b667c4b5c97230f7e8d805b25d to your computer and use it in GitHub Desktop.
Java:
@GetMapping("/users/nome/{nome}")
@Query(value = "SELECT * FROM USUARIO WHERE NOME LIKE '%:nome%'", nativeQuery = true)
List<User> getUserByName(@PathVariable(value = "nome") String nome) throws ResourceNotFoundException {
List<User> users = userRepository.findByNome(nome);
if (users.isEmpty()) {
throw new ResourceNotFoundException("User not found for this name: " + nome);
}
return users;
}
Response:
[{"id":1000078,"sigla":"email@gmail.com.br","nome":"LUCAS PAULINO MARRA"},
{"id":100001635,"sigla":"sigla","nome":"LUCAS PAULINO MARRA"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment