亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:58日期: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 { /** * 獲取賬號(hào)最新的一個(gè)數(shù)據(jù)(指單個(gè)字段,例如最新時(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這里就不寫(xiě)了,很普通,只說(shuō)重點(diǎn)!

看下官方文檔的解釋:

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

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

補(bǔ)充知識(shí):【spring data jpa】根據(jù)一個(gè)時(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í)例代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 毛片应用| 男人天堂综合网 | 国产一区系列在线观看 | 欧美h版无删完整大片 | 高清在线一区二区三区亚洲综合 | 国产一级高清视频免费看 | 鲁大师手机在线观看视频 | 国产精彩对白综合视频 | 久久最新免费视频 | 一区在线观看视频 | 国产精品国产三级国产专区不 | 日韩免费高清视频网站 | 国产免费爽爽视频免费可以看 | 黄色一级片免费播放 | 国产欧美一区二区三区鸳鸯浴 | 欧美色图一区二区 | 麻豆视频官网 | 国产成人v爽在线免播放观看 | 三级网址在线播放 | 男女爱爱免费网站视频在线观看 | 手机国产日韩高清免费看片 | 国产福利在线观看第二区 | 亚洲一区二区欧美 | 黄色在线免费 | 久久99精品久久久久久黑人 | 中文字幕片 | 免费播放观看视频大片 | 亚洲国产成人精品区 | 国产精品主播视频 | 国产在线观看91精品2022 | 日本一级爽毛片在线看 | 亚洲图片色 | 黄污视频免费观看 | 国产精品v免费视频 | 日韩亚洲在线观看 | 国产人免费人成免费视频 | 欧美ol丝袜高跟秘书在线播放 | 美女一级黄色 | 成人在色线视频在线观看免费大全 | 国产欧美精品一区二区 | 国产麻豆91网在线看 |