SOURCE CODE (GitHub Link)
https://github.com/VikramThakur8/Enqu...
PURPOSE:
This video covers fetching full detail of enquiry based on enquiryId primary key. Its using Spring Data API Map Based Projection to bind the selected columns of Hibernate-JPQL @Query. Spring Data JPA makes database handing so easy for java developer. Thymeleaf Template is used in UI.
SOURCE CODE REFERENCE:
1. Controller Method:
@GetMapping("/enquiry-detail/{id}")
public String enquiryDetail(@PathVariable Long id, Model m){
m.addAttribute("dataMap", enquiryRepository.getEnquiryDetailMap(id));
m.addAttribute("followupList", followupRepository.getFollowupsByEnquiryId(id));
return "/enquiry-detail"; //html
}
2. Repository Methods and Query:
//Enquiry Repository method:
@Query("SELECT e.enquiryId AS enquiryId, e.doe AS doe,e.nextCallDate AS nextCallDate , e.committedFees AS fees, e.remark AS remark, "
" e.enquirySource.name AS sourceOfEnquiry, "
" c.name AS name, c.phone AS phone, c.email AS email,"
" c.permanentAddress.city AS city, c.permanentAddress.country AS country, c.permanentAddress.zip AS zip, c.permanentAddress.detail AS detail,"
" (SELECT group_concat(co.name) FROM Course co, EnquiryCourse ec WHERE e=ec.enquiry AND ec.course=co) AS courses "
" FROM Enquiry e, Contact c WHERE e.contact=c and e.enquiryId=?1")
public Map getEnquiryDetailMap(Long enquiryId);
//FollowupRepository method:
@Query("SELECT new Followup(f.followupId, f.doe, f.detail) FROM Followup as f WHERE f.enquiry.enquiryId=?1 ORDER BY f.doe desc")
List of Followup getFollowupsByEnquiryId(Long enquiryId);
3. THYMELEAF TEMPLATE REFERENCE CODE:
Download from GitHub Link mentioned above.
TECHNOLOGY USED:
Java 8, Spring Boot, Spring Data JPA, MySQL Database, NetBeans IDE, Hibernate JPA Implementation, Maven, MySQL Workbench, JSON, MicroServices.
PREVIOUS VIDEO IN CASE YOU MISSED:
• 10 - Spring Data JPA | Spring Boot | Proje...
#SpringBoot #SpringData #JPA_Hibernate #Spring