zoukankan      html  css  js  c++  java
  • json 转换实体对象

    import javax.servlet.http.HttpServletRequest;

    import com.aliyuncs.utils.StringUtils;
    import com.sinosoft.cms.entity.CoreOrganization;

    import net.sf.json.JSONObject;
    import net.sf.json.JsonConfig;
    import net.sf.json.util.JavaIdentifierTransformer;

    public void coreImport(JSONObject requestJson, HttpServletRequest request) {
    String data = requestJson.getString("data");
    JSONObject jsonObject =JSONObject.fromObject(data);

    //CoreOrganization entInfo = (CoreOrganization)JSONObject.toBean(jsonObject, CoreOrganization.class);//会导致参数不对对象为空
    CoreOrganization entInfo = (CoreOrganization)JSONObject.toBean(jsonObject, getJsonConfig(CoreOrganization.class));

    }

    private JsonConfig getJsonConfig(Class clazz) {
    JsonConfig config = new JsonConfig();
    config.setJavaIdentifierTransformer(new JavaIdentifierTransformer() {

    @Override
    public String transformToJavaIdentifier(String str) {
    if(StringUtils.isEmpty(str)){
    return str;
    }
    return str.substring(0,1).toLowerCase().concat(str.substring(1));
    }
    });
    config.setRootClass(clazz);
    return config;
    }

    qq 891451702
  • 相关阅读:
    mysql 优化
    对象的特征
    对象的回收机制
    对象产生的过程
    python 内容查询小助手
    python笔记
    python安装MySQLdb模块
    python笔记
    python笔记
    定期删除备份文件,节省磁盘空间脚本
  • 原文地址:https://www.cnblogs.com/duoyan/p/15458785.html
Copyright © 2011-2022 走看看