日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringData 简单的条件查询

發布時間:2024/4/17 javascript 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringData 简单的条件查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天在寫springdata條件查詢時,JpaRepository的findOne方法,不知道是因為版本的原因還是其他原因,總是查詢不出來數據

  //springdata jpa版本為1.5.15,配置1.5.18的springboot版本
  public
User getUserByEmail(String email){User u=new User();u.setUserEmail(email);Example<User> example=Example.of(u);User admin=null;admin=userRepository.findOne(example);return admin;}

另外,在之前用SpringBoot2.0版本時

Optional<User> admin=userRepository.findOne(example);

admin.isPresent()的值也為false,也取不到值!

解決辦法:SpringData的簡單查詢方法

1.在JpaRepository下添加方法

package com.fdzang.mblog.repository;import com.fdzang.mblog.pojo.User; import org.springframework.data.jpa.repository.JpaRepository;public interface UserRepository extends JpaRepository<User,String> {User getByUserEmail(String userEmail); }

2.在service下使用該方法

package com.fdzang.mblog.service;import com.fdzang.mblog.pojo.User; import com.fdzang.mblog.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;@Service public class UserService {@AutowiredUserRepository userRepository;/*** 通過郵箱得到用戶信息* @param email* @return*/public User getUserByEmail(String email){User admin=null;admin=userRepository.getByUserEmail(email);return admin;} }

3.總結

直接在接口中定義查詢方法,如果是符合規范的,可以不用寫實現,目前支持的關鍵字寫法如下:

4.查詢方法解析

?

?5.使用@Query注解

?

?

?

轉載于:https://www.cnblogs.com/fdzang/p/9560054.html

總結

以上是生活随笔為你收集整理的SpringData 简单的条件查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。