av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Spring Date jpa 獲取最新一條數(shù)據(jù)的實(shí)例代碼

瀏覽:82日期:2023-08-10 14:58:30

#Repository

import test.demo.domain.entity.TestEntity;import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;import org.springframework.stereotype.Repository;@Repositorypublic interface TestEntityRepository extends JpaRepositoryImplementation<TestEntity,Integer> {}

#Service

import org.springframework.validation.annotation.Validated;import javax.validation.constraints.NotBlank;@Validatedpublic interface TestService { /** * 獲取賬號最新的一個數(shù)據(jù)(指單個字段,例如最新時(shí)間,最新年齡等) * @param username * @return */ String findLastage(@NotBlank String username);}

#ServiceImpl

import test.demo.domain.entity.TestEntity;import test.demo.repository.TestEntityRepository;import test.demo.service.TestService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.domain.PageRequest;import org.springframework.data.domain.Sort;import org.springframework.stereotype.Service;import java.time.LocalDateTime;import java.util.List;@Servicepublic class TestServiceImpl implements TestService { @Autowired private TestEntityRepository testEntityRepository; @Override public String findLastAge(String username) { Sort createTime = new Sort(Sort.Direction.DESC, 'createTime'); PageRequest of = PageRequest.of(0, 1, createTime); List<TestEntity> testEntities= testEntityRepository.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.and(criteriaBuilder.equal(root.get('age'), age),criteriaBuilder.lessThan(root.get('expiredTime'), LocalDateTime.now()) ))); if (testEntities.isEmpty()){ return null; } String age = TestEntities.get(0).getCode(); return age; }}

Entity這里就不寫了,很普通,只說重點(diǎn)!

看下官方文檔的解釋:

Spring Date jpa 獲取最新一條數(shù)據(jù)的實(shí)例代碼

Spring Date jpa 獲取最新一條數(shù)據(jù)的實(shí)例代碼

補(bǔ)充知識:【spring data jpa】根據(jù)一個時(shí)間字段 查詢 時(shí)間段的處理方法

處理方法 包含結(jié)束時(shí)間00.00.00

Date createDate = boxCodeLog.getCreateDate();if (createDate != null){ LocalDate localDate=createDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); localDate = localDate.plusDays(1); Date endDate = java.sql.Date.valueOf(localDate); predicates.add(cb.between(root.get('createDate'),createDate,endDate));}

包含結(jié)束時(shí)間 23.59.59

Date createDate = receipt.getCreateDate();if (createDate != null){ LocalDate localDate=createDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); localDate = localDate.plusDays(1); Date endDate = new Date(java.sql.Date.valueOf(localDate).getTime()-1L); predicates.add(cb.between(root.get('createDate'),createDate,endDate));}

以上這篇Spring Date jpa 獲取最新一條數(shù)據(jù)的實(shí)例代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 国产高清一区二区三区 | 欧美9999 | 欧美成人精品一区二区男人看 | 国产精品日韩一区二区 | 自拍视频精品 | 九九九视频精品 | 亚洲国产乱码 | 久久精品女人天堂av | 亚洲一区二区三区在线播放 | 欧美日韩在线观看视频网站 | 欧美男人天堂 | 日韩在线国产 | 亚洲深夜福利 | 91精品国产综合久久久久蜜臀 | 国产一区999| 青青久视频 | 日本色婷婷 | 国产日韩久久 | 日日夜夜草 | 一色桃子av一区二区 | 天天操夜夜操 | 午夜三区 | 亚洲一区二区三区在线视频 | 天天操网 | 亚洲www.| 日韩中文一区二区 | 91免费入口 | 亚洲一区精品在线 | 国产粉嫩尤物极品99综合精品 | 久久出精品 | 亚洲成人一区二区三区 | 国产一区二区a | www.操com | 亚洲精品日韩视频 | 国产在线视频一区 | 日韩一级免费电影 | 国产成人精品一区二区三区四区 | 午夜电影网站 | 国产精品久久久久一区二区 | 精品国产18久久久久久二百 | 精品一区二区在线观看 |