I want to search by email but always get "error": "Not Acceptable",
@RestController
@RequestMapping("api/users")
public class UserController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping(value = "/{name:.+}")
public User getUser(@PathVariable String name) {
return userService.getUserByEmail(name);
}
@Service
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
public UserServiceImpl(UserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public User getUserByEmail(String email){
User user = userRepository.findByEmail(email).get();
return user;
}
@Repository
public interface UserRepository extends JpaRepository<User,Long> {
Optional<User> findByEmail(@Param("email") String email);
}
even It can fetch from database but when want to return throw error
add header application/json header but don't work.
another thing that I can get byId and firstName ,this work correctly