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)文章:
主站蜘蛛池模板: 日韩欧美三级电影在线观看 | 99色综合 | 国产日韩一区二区三区 | 天堂综合网| 国产综合在线视频 | 久久久久久久久久性 | 精品96久久久久久中文字幕无 | 精品一区二区免费视频 | 亚洲高清免费 | 久久草在线视频 | 天天草天天射 | 国产婷婷色综合av蜜臀av | 日韩欧美高清dvd碟片 | 在线国产精品一区 | 国产精品一区二区在线观看 | 欧美黄色免费网站 | 国产在线一区二区三区 | 天天爽夜夜爽精品视频婷婷 | 亚洲一区二区三区福利 | 综合成人在线 | 日韩中出 | 一区二区久久精品 | 日本不卡一区二区三区在线观看 | 91影院 | 奇米超碰 | 毛片区 | 日本三级网站在线 | 国产成人精品a视频一区www | 超碰520| 亚洲欧美国产精品久久 | 国产精品久久久久久吹潮 | 色欧美片视频在线观看 | 精品不卡 | 一级毛片免费 | 蜜桃免费一区二区三区 | 国产在线不卡 | 99精品国自产在线 | 国产农村妇女毛片精品久久麻豆 | 国产福利视频 | 91大神在线资源观看无广告 | 国产免费av在线 |