Java Traversal list fuzzy query with
1 /**2 * Filter List3 * @paramList to filter by list4 * @paramKey filtered by key5 * @param<T>6 * @return7 */8 Private<T> list<t> Search (list<t>list, String key) {9 //if the value of the query is not empty, walk in and return the value after the search, otherwise return the original valueTen if(List! =NULL&& list.size () > 0) { One //New Container Alist<t> area =NewArraylist<>(); - BooleanisOK; - //Cyclic olist Collection the for(T t:list) { - //judge a inside if contains the value of the search, there is added, no otherwise will not add (will find the property name) - //if (t.tostring (). toUpperCase (). indexOf (str)! =-1) - //Area.add (t); +isOK =false; - //traversing entity classes, getting property names and property values + for(Field field:t.getclass (). Getdeclaredfields ()) { AField.setaccessible (true); at //Here are the properties that you specify to check - //item_firstletter item_name item_col1 - Switch(Field.getname ()) { - Case"Item_firstletter": - Try { -isOK =Field.get (t). ToString (). Contains (key); in}Catch(illegalaccessexception e) { - e.printstacktrace (); to } + Break; - Case"Item_name": the Try { *isOK =Field.get (t). ToString (). Contains (key); $}Catch(illegalaccessexception e) {Panax Notoginseng e.printstacktrace (); - } the Break; + Case"Item_col1": A Try { theisOK =Field.get (t). ToString (). Contains (key); +}Catch(illegalaccessexception e) { - e.printstacktrace (); $ } $ Break; - } - if(isOK) the Break; - }Wuyi if(isOK) the Area.add (t); - } Wu returnArea ; -}Else { About return NewArrayList (); $ } -}
Java Traversal list fuzzy query with