Spring Data JPA Query

Source: Internet
Author: User

@Componentpublic interface Taskdao extends Pagingandsortingrepository<task, long>, Jpaspecificationexecutor <Task> {page<task> Findbyuserid (Long ID, pageable pagerequest); @Modifying @query ("Delete from task task where task.user.id=?1 ") void Deletebyuserid (Long id);}



Public page<task> getusertask (long userid, map<string, object>  Searchparams, int pagenumber, int pagesize,string sorttype)  {PageRequest  Pagerequest = buildpagerequest (Pagenumber, pagesize, sorttype); Specification<task> spec = buildspecification (Userid, searchparams);return  Taskdao.findall (spec, pagerequest);} /** *  Create a paging request.  */private pagerequest buildpagerequest (Int pagenumber, int  pagzsize, string sorttype)  {Sort sort = null;if  ("Auto". Equals ( SortType))  {sort = new sort (direction.desc,  "id");}  else if  ("title". Equals (SortType))  {sort = new sort (direction.asc,  " Title ");} Return new pagerequest (Pagenumber - 1, pagzsize, sort);} /** *  Create dynamic query condition combinations.  */private specification<tAsk> buildspecification (long userid, map<string, object> searchparams)   {Map<string, searchfilter> filters = searchfilter.parse (searchParams); Filters.put (" User.ID ",  new searchfilter (" User.ID ",  operator.eq, userid)); Specification<task> spec = dynamicspecifications.bysearchfilter (Filters.values (),  Task.class); return spec;}

Spring Data JPA query (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.