Repository
@Repository
public interface UserJpaRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USER WHERE EMAIL = ?", nativeQuery = true)
Optional<User> findByEmail(String email);
}
}
Service
@Override
public User getByEmail(String email) {
Optional<User> userDB = repo.findByEmail(email);
if (userDB.isPresent()) {
return userDB.get();
}
else {
throw new ResourceNotFoundException("record not found with this id: " + email);
}
}
Controller
@GetMapping("/get/{email}")
public User showByEmail(@RequestParam(value = "email") String email) {
return userService.getByEmail(email);
}
Error
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for '/get/snvairagi003@gmail.com': {public com.example.model.User com.example.controller.UserController.showById(java.lang.Long), public com.example.model.User com.example.controller.UserController.showByEmail(java.lang.String)}] with root cause

java.lang.IllegalStateException: Ambiguous handler methods mapped for '/get/snv': {public com.example.model.User com.example.controller.UserController.showById(java.lang.Long), public com.example.model.User com.example.controller.UserController.showByEmail(java.lang.String)}