Last active
June 23, 2019 02:55
-
-
Save jmimi/3dd7ab196ec809861532039523b8a33d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Value | |
class WhatsappChatDTO{ | |
String whatssappid, name; | |
} | |
// or comment above and uncomment below | |
/* | |
interface WhatsappChatDTO{ | |
String getWhatsappid(); | |
String getName(); | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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