This file contains 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
@Component | |
public class MapperUtility { | |
public CustomerOrderDTO buildOrderDTO(Long orderNumber, Double totalAmount) { | |
CustomerOrderDTO customerOrderDTO = null; | |
if (orderNumber != null) { | |
customerOrderDTO = new CustomerOrderDTO(); | |
customerOrderDTO.setOrderNumber(orderNumber); | |
customerOrderDTO.setTotalAmount("$" + totalAmount); |
This file contains 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
public List<CustomerDetailsDTO> getCustomersAndOrderData() throws Exception { | |
return customerRepository.getCustomerDetails(); | |
} |
This file contains 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 CustomerRepository extends JpaRepository<CustomerEntity, Integer> { | |
@Query(name = "customerEntity.getCustomerDetails", nativeQuery = true) | |
List<CustomerDetailsDTO> getCustomerDetails(); | |
} |
This file contains 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 CustomerServiceImpl implements CustomerService { | |
@Autowired | |
private CustomerRepository customerRepository; | |
public List<CustomerDetailsDTO> getCustomersAndOrderData() throws Exception { | |
return customerRepository.getCustomerDetails(); | |
} | |
} |
This file contains 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
@RestController | |
public class CustomerController { | |
@RequestMapping(value = "/customers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | |
public List<CustomerDetailsDTO> getCustomers() throws Exception { | |
return customerService.getCustomersAndOrderData(); | |
} | |
} |
This file contains 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
@Component | |
public class MapperUtility { | |
public OrderDTO buildOrderDTO(Long orderNumber, Double totalAmount) { | |
OrderDTO order = new OrderDTO(); | |
order.setOrderNumber(orderNumber); | |
order.setTotalAmount("$" + totalAmount); | |
return order; | |
} | |
} |
This file contains 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
[ | |
{ | |
"country": "Spain", | |
"city": "Madrid", | |
"customerId": 10001, | |
"customerName": "Diego Roel" | |
}, | |
{ | |
"country": "France", | |
"city": "Paris", |
This file contains 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
@Data | |
@Entity | |
@Table(name = "CUSTOMER_ORDER") | |
public class OrderEntity { | |
@Id | |
@Column(name = "ID") | |
private Integer id; | |
@Column(name = "ORDER_NUMBER") |
This file contains 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
@Data | |
@Entity | |
@Table(name = "CUSTOMER") | |
public class CustomerEntity { | |
@Id | |
@Column(name = "ID") | |
private Integer id; | |
@Column(name = "FIRST_NAME") |
This file contains 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
<named-native-query name="customerEntity.getCustomerDetails"> | |
<query><![CDATA[ | |
SELECT | |
cust.id as customerId, | |
cust.FIRST_NAME as firstName, | |
cust.LAST_NAME as lastName, | |
cust.CITY as city, | |
cust.COUNTRY as country, | |
corder.ORDER_NUMBER as orderNumber, | |
corder.TOTAL_AMOUNT as totalAmount |
OlderNewer