这里新来的Spring,从在线资源中学习,有疑问。谁能解释一下吗?我指的是链接https://www.springboottutorial.com/creating-microservices-with-spring-boot-part-2-forex-microservice。
我能够创造一切,如预期,并看到结果。我理解Restcontroller,并且很难理解下面的代码。
请有人解释一下,我应该如何阅读/理解下面的代码,以及如何知道发生了什么?请注意,我没有收到任何错误。我在本地服务器上得到了预期的响应。据我所知,这个方法findByFromAndTo在接口中没有任何实现,但在RestController中也没有任何实现。这是怎么回事?
public interface ExchangeValueRepository extends
JpaRepository<ExchangeValue, Long> {
ExchangeValue findByFromAndTo(String from, String to);
}发布于 2020-04-06 05:17:55
ExchangeValue findByFromAndTo(String from, String to); 在上面的语句中,ExchangeValue是预期的响应。有两个列,我们必须找到的是从和到。
用法:如果我们想查询从一种货币到另一种货币的换算值。从数据库中获取交换值。
如果我们想要根据单个列查找数据,我们可以传递一个列名。例如:
ExchangeValue findByFrom (String from); 内部工作:
我们将使用JPA标准API创建一个查询,但从本质上讲,这将转换为以下查询:
select e from ExchangeValue e where e.from = ?1 and e.to = ?2Spring数据JPA将执行属性检查并遍历嵌套属性,如??中所述。
如果And是关键字,findByLastnameAndFirstname是示例,那么JPQL片段/查询是…where x.lastname = ?1 and x.firstname = ?2
官方文档的更多详细信息:https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/jpa.repositories.html
希望这能帮上忙!
https://stackoverflow.com/questions/61050853
复制相似问题