Several methods used in the tool class for generating dynamic conditions using jfinal

Source: Internet
Author: User

In fact, both model and record belong to map, but in some cases, you still need to convert the attributes and values in the model or record into a map key-value pair, because the field and value need to be transferred during buildcondition, in order to share a method and unify it, the model and record are all converted into a map and passed to buildcondition, and such conversion is also required elsewhere, for example, if you directly pass a model to the front-end page and it seems that you cannot obtain the attributes of the model, you need to convert it yourself! Therefore, we have written these two methods.

1. Convert the model to map

/*** Convert the model class to map modeltomap ** @ Param parameter description * @ return returns the object * @ exception object */public static Map <string, object> modeltomap (Model <?> Model) {Map <string, Object> map = new hashmap <string, Object> (); string [] names = model. getattrnames (); For (string STR: names) {map. put (STR, model. get (STR);} return map ;}

2. convert a record to a map

/*** Convert a record to map recordtomap ** @ Param parameter description * @ return returns the object * @ exception object */public static Map <string, object> recordtomap (record) {Map <string, Object> map = new hashmap <string, Object> (); If (record! = NULL) {string [] Columns = record. getcolumnnames (); For (string Col: columns) {map. put (COL, record. get (COL) ;}} return map ;}

3. Check whether the object is empty.

/*** Determines whether each object in the object or object array is null: the object is null, And the Character Sequence length is 0, set class and map to empty ** @ Param OBJ * @ return */@ suppresswarnings ("unchecked") public static Boolean isnullorempty (Object OBJ) {If (OBJ = NULL) {return true;} else if (OBJ instanceof string & (obj. equals ("") {return true;} else if (OBJ instanceof short & (short) OBJ ). repeated value () = 0) {return true;} else if (OBJ instanceof integer & (integer) ob J ). intvalue () = 0) {return true;} else if (OBJ instanceof double & (double) OBJ ). doublevalue () = 0) {return true;} else if (OBJ instanceof float & (float) OBJ ). floatvalue () = 0) {return true;} else if (OBJ instanceof long & (long) OBJ ). longvalue () = 0) {return true;} else if (OBJ instanceof Boolean &&! (Boolean) OBJ) {return true;} else if (OBJ instanceof Collection & (Collection) OBJ ). isempty () {return true;} else if (OBJ instanceof map & (MAP) OBJ ). isempty () {return true;} else if (OBJ instanceof object [] & (object []) OBJ ). length = 0) {return true;} return false ;}

Several methods used in the tool class for generating dynamic conditions using jfinal

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.