In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "introduction and basic usage of Spring Data JPA". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Yesterday we introduced Spring Data JPA, as well as basic use, today we talk about paging.
First, we modify the RaindropUserRepository class
Import org.springframework.data.domain.Pageable;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.data.jpa.repository.Query;import run.halo.app.model.entity.*;import java.util.List;public interface RaindropUserRepository extends JpaRepository {RaindropUser findByUsername (String userName); RaindropUser findBySexAndEmail (String sex, String email) / / modify method-add Pageable class @ Query ("select new run.halo.app.model.entity.RaindropUser (raindrop.id," + "raindrop.username,raindrop.email,raindrop.sex," + "raindrop.age) from RaindropUser raindrop where raindrop.age)
< ?1") List findByLtAge(Integer age, Pageable pageable);// @Query("select new run.halo.app.model.entity.RaindropUser(a.id,a.username,a.email,a.sex,a.age) from spring_data_jpa a where age >1 ") / / RaindropUser findByRtAge (Integer age);}
Then we modify the test method:
@ Test public void Test () {/ / set page number to 0, number of displays per page 15 int page=0,size=15;//, sort by id column in descending order, ascending order as Sort.Direction.ASC Sort sort = new Sort (Sort.Direction.DESC, "id"); / / set Pageable variable Pageable pageable = PageRequest.of (page, size, sort); List list = raindropUserRepository.findByLtAge (15, pageable) System.out.println ("List:" + list.get (0));}
View console print information:
Hibernate: select raindropus0_.id as col_0_0_, raindropus0_.username as col_1_0_, raindropus0_.email as col_2_0_, raindropus0_.sex as col_3_0_, raindropus0_.age as col_4_0_ from springdatajpa raindropus0_ where raindropus0_.age
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.