Skip to content

Instantly share code, notes, and snippets.

@jmimi
Last active June 23, 2019 02:55
Show Gist options
  • Save jmimi/3dd7ab196ec809861532039523b8a33d to your computer and use it in GitHub Desktop.
Save jmimi/3dd7ab196ec809861532039523b8a33d to your computer and use it in GitHub Desktop.
@Value
class WhatsappChatDTO{
String whatssappid, name;
}
// or comment above and uncomment below
/*
interface WhatsappChatDTO{
String getWhatsappid();
String getName();
}
*/
@Repository
public interface WhatsappChatRepository extends JpaRepository<WhatsappChat, Long>{
@Query("SELECT DISTINCT W.whatsappid, W.name FROM WhatsappChat W")
List<WhatsappChatDTO> findAllContacts();
}
// say you have Long for entity id
//By this repository you don't need to convert your entities to DTO's. It is converted implicitly
@Service
public class WhatsappChatService{
@Autowired
private WhatsappChatReposiotry repository;
public List<WhatsappChatDTO> listAllContacts(){
return repository.findAllContacts();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment