qq_35785520 2017-08-09 09:40 采纳率: 0%
浏览 472

springmvc 这个方法的用法谁懂

public static final T getModelMapObject(Class type, String modelMapAttrKey, HttpServletRequest request, ModelMap modelMap, T defaultValue) {
T modelMapAttrValue = defaultValue;

    if (null != type && null != modelMapAttrKey) {
        Object modelMapAttrValueObject = null;

        if (null != modelMap) {
            modelMapAttrValueObject = modelMap.get(modelMapAttrKey);
        } // if (null != modelMap)

        if (null == modelMapAttrValueObject && null != request) {
            modelMapAttrValueObject = request.getAttribute(modelMapAttrKey);
            if (null != modelMapAttrValueObject && null != modelMap) {
                modelMap.addAttribute(modelMapAttrKey, modelMapAttrValueObject);
            } // if (null != modelMapAttrValueObject && null != modelMap)
        } // if (null == modelMapAttrValueObject && null != request)

        if (null != modelMapAttrValueObject) {
            if (modelMapAttrValueObject.getClass() == type) {
                modelMapAttrValue = (T) modelMapAttrValueObject;
            } else {
                if (Boolean.class == type && modelMapAttrValueObject instanceof Integer) {
                    if (1 == (Integer) modelMapAttrValueObject) {
                        modelMapAttrValue = (T) new Boolean(true);
                    } else {
                        modelMapAttrValue = (T) new Boolean(false);
                    }
                } else if (Map.class == type && modelMapAttrValueObject instanceof Map) {
                    modelMapAttrValue = (T) modelMapAttrValueObject;
                } else if (List.class == type && modelMapAttrValueObject instanceof List) {
                    modelMapAttrValue = (T) modelMapAttrValueObject;
                }
            }
        } // if (null != modelMapAttrValueObject)
    } // if (null != type && null != modelMapAttrKey)

    return modelMapAttrValue;
}
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2018-06-14 16:27
    关注
    评论

报告相同问题?