Java Code Examples for com.jfinal.plugin.activerecord.Model#get()

The following examples show how to use com.jfinal.plugin.activerecord.Model#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StrUtil.java    From jboot with Apache License 2.0 6 votes vote down vote up
public static Model escapeModel(Model model, String... ignoreAttrs) {
    String[] attrNames = model._getAttrNames();
    for (String attr : attrNames) {

        if (ArrayUtils.contains(ignoreAttrs, attr)) {
            continue;
        }

        Object value = model.get(attr);

        if (value != null && value instanceof String) {
            model.set(attr, escapeHtml(value.toString()));
        }
    }

    return model;
}
 
Example 2
Source File: JsonUtils.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 把model转为map,驼峰命名
 *
 * @param model
 * @return
 */
public static Map<String, Object> modelToCamelCaseMap(Model model) {
    if (null == model) {
        return null;
    }
    String[] keys = model._getAttrNames();
    Map<String, Object> map = new HashMap<>();
    for (String key : keys) {
        Object value = model.get(key);
        key = StrKit.toCamelCase(key.toLowerCase());
        if (null != value) {
            map.put(key, value);
        }
    }
    return map;
}
 
Example 3
Source File: CommonsUtils.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 防止 model 存储关于 xss 相关代码
 *
 * @param model
 */
public static void escapeModel(Model model, String... ignoreAttrs) {
    String[] attrNames = model._getAttrNames();
    for (String attr : attrNames) {

        if (ArrayUtils.contains(ignoreAttrs, attr)) {
            continue;
        }

        Object value = model.get(attr);

        if (value != null && value instanceof String) {
            model.set(attr, StrUtil.escapeHtml(value.toString()));
        }
    }
}
 
Example 4
Source File: ModelExt.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
/**
 * check current instance is equal obj or not.[wrapper equal]
 * @param obj
 * @return true:equal, false:not equal.
 */
public boolean eq(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (this._getUsefulClass() != obj.getClass())
           return false;
       
       Model<?> other = (Model<?>) obj;
       Table tableinfo = this.table();
       Set<Entry<String, Object>> attrsEntrySet = this._getAttrsEntrySet();
       for (Entry<String, Object> entry : attrsEntrySet) {
           String key = entry.getKey();
           Object value = entry.getValue();
           Class<?> clazz = tableinfo.getColumnType(key);
           if (clazz == Float.class) {
           } else if (clazz == Double.class) {
           } else if (clazz == Model.class) {
           } else {
               if (value == null) {
                   if (other.get(key) != null)
                       return false;
               } else if (!value.equals(other.get(key)))
                   return false;
           }
       }
       return true;		
}
 
Example 5
Source File: ControllerBase.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean isLoginedUserModel(Model model, String attrName) {
    if (model == null) {
        return false;
    }
    Object userId = model.get(attrName);
    if (userId == null) {
        return false;
    }
    User loginedUser = getLoginedUser();
    if (loginedUser == null) {
        return false;
    }
    return userId.equals(loginedUser.getId());
}
 
Example 6
Source File: JsoupUtils.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void clean(Model model, String... attrs) {
    if (attrs != null && attrs.length == 0) {
        return;
    }

    for (String attr : attrs) {
        Object data = model.get(attr);
        if (data == null || !(data instanceof String)) {
            continue;
        }

        model.set(attr, clean((String) data));
    }
}
 
Example 7
Source File: AdminControllerBase.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected boolean validateSlug(Model model) {
    String slug = (String) model.get("slug");
    return slug == null ? true : !slug.contains("-") && !StrUtil.isNumeric(slug);
}
 
Example 8
Source File: ArticleUCenterController.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean validateSlug(Model model) {
    String slug = (String) model.get("slug");
    return slug == null ? true : !slug.contains("-");
}