springboot

JPA query 基本语法解释

2019-06-18  本文已影响0人  有点意思_yxwn

JPA query 基本语法解释

JPA query 基本语法解释

详细语法官网去学习 -->> http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference

                              摘抄2018.02.19版本: [http://www.cnblogs.com/wangdaijun/p/8482073.html](http://www.cnblogs.com/wangdaijun/p/8482073.html)

Query creation

Generally the query creation mechanism for JPA works as described in Query methods. Here’s a short example of what a JPA query method translates into:

Example 43. Query creation from method names

<pre style="padding: 1em; line-height: 1.45; color: rgba(0, 0, 0, 0.9); border-bottom: 1px solid rgb(204, 204, 204); font-family: "Droid Sans Mono", "DejaVu Sans Mono", monospace; font-size: 1em; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; word-break: break-word; box-sizing: border-box; direction: ltr; border: 1px solid rgb(224, 224, 220); border-radius: 4px; box-shadow: rgb(224, 224, 220) 0px 1px 4px; background: rgb(247, 247, 248); overflow-wrap: break-word; text-rendering: optimizespeed;">public interface UserRepository extends Repository<User, Long> { List<User> findByEmailAddressAndLastname(String emailAddress, String lastname); }
</pre>

We will create a query using the JPA criteria API from this but essentially this translates into the following query:select u from User u where u.emailAddress = ?1 and u.lastname = ?2. Spring Data JPA will do a property check and traverse nested properties as described in Property expressions. Here’s an overview of the keywords supported for JPA and what a method containing that keyword essentially translates to.

上一篇下一篇

猜你喜欢

热点阅读