Hrishikesh Shinde
Hrishikesh Shinde

Reputation: 39

Return boolean result from getmapping using jparepository

This is my getmapping controller
@GetMapping("/email")
    public List<user> doesUsernameExists(@RequestParam String username) throws IOException, InterruptedException{
        System.out.println("Inside doesUsernameExists");        
        return this.usernameExists.findByUsername(username);
    }
This is my JpaRepository interface
@Repository
public interface usernameExists extends JpaRepository<user, Long>{  
    List<user> findByUsername(String userName); 
}

This code is working fine but it is giving response in json with id username and password.But, I want to return true if username exists in db table otherwise false what should I do please help .

Upvotes: 0

Views: 434

Answers (1)

Hrishikesh Shinde
Hrishikesh Shinde

Reputation: 39

@Repository
public interface usernameExists extends JpaRepository<user, Long>{
    
    boolean existsByUsername(String userName);
    
}

@Autowired
    private usernameExists usernameExists;
    
    @CrossOrigin(origins = "*")
    @GetMapping("/email")
    public boolean doesUsernameExists(@RequestParam String username) throws IOException, InterruptedException{
        System.out.println("Inside doesUsernameExists");
        
        return this.usernameExists.existsByUsername(username);
    }

this solved the problem

Upvotes: 1

Related Questions