Get a collection of dynamic conditions
list<long> list =NewArraylist<long>(); Long Sysuserid=Currentuser.getsysuserid (); if(Sysuserid! =NULL) {Sysuser Sysuser=Sysuserrepository.findone (Sysuserid); if(Sysuser! =NULL) {String groupitemids=Sysuser.groupitemids (); if(Groupitemids! =NULL&&!Groupitemids.isempty ()) {string[] str= Stringutils.split (Groupitemids, ","); for(String s:str) {if(s! =NULL&&!s.isempty () && s! = "") {List.add (long.valueof (s)); } } } } }
Package Specification Query criteria
Specification<goods> spec = (root, query, CB){List<Predicate> predicates =NewArraylist<predicate>();List<Predicate> prelist =NewArraylist<predicate>(); if(List! =NULL&& list.size () >0{ prelist.add (root). <long>get ("Groupitemid" ). In (list)); } if(Sysuserid! =NULL) {predicate predicate =cb.equal (Root.get (Goods_.crtuserid), Sysuserid); Prelist.add (predicate); } predicate P = Cb.or (Prelist.toarray (new predicate[prelist.size ())); Predicates.add (p); if(!Predicates.isempty ()) { returnCb.and (Predicates.toarray (NewPredicate[0])); } Else { return NULL; } }; Page<Goods> Pageresult = Goodsrepository.findall (spec, pageable);
SPRING-DATA-JPA Dynamic Condition Query