Reputation: 131
New to Spring Boot here, learning from online resource, have question. Can someone please explain me? I am referring from link https://www.springboottutorial.com/creating-microservices-with-spring-boot-part-2-forex-microservice
.
I am able to create everything as expected and see the results. I understood Restcontroller, and have trouble understanding below lines.
Can someone please explain me how shall I read / understand below code and how to know what's happening? Please note I am not getting any error. I get the response at my local server as expected. This method findByFromAndTo
does not have any implementation in interface which I understand but it does not have any implementation in RestController as well. So how does this work?
public interface ExchangeValueRepository extends
JpaRepository<ExchangeValue, Long> {
ExchangeValue findByFromAndTo(String from, String to);
}
Upvotes: 0
Views: 249
Reputation: 2209
ExchangeValue findByFromAndTo(String from, String to);
In the above statement, ExchangeValue is the expected response. There are two columns that we have to find are from and to.
Usage: If we want to query the conversion value from one currency to another. Get the exchange value from the database.
If we want to find data on the basis of single column, we can pass a column name. For example:
ExchangeValue findByFrom (String from);
Internal Working:
We will create a query using the JPA criteria API from this but essentially this translates into the following query:
select e from ExchangeValue e where e.from = ?1 and e.to = ?2
Spring Data JPA will do a property check and traverse nested properties as described in ???.
If And
is the Keyword,
findByLastnameAndFirstname
is the sample,
then JPQL snippet/query is … where x.lastname = ?1 and x.firstname = ?2
More details from official documentation: https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/jpa.repositories.html
Hope this helps.!
Upvotes: 1