• 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
  • 相关阅读:
    SQL语句大全
    网页常用小技巧
    卡通时钟代码
    舒服的颜色2
    静态代码
    Hibernate工作原理
    SQl多表查询优化 高效率SQL语句
    Hibernate API、对象状态、HQL、Criteria
    MySQL 学习笔记
    intramart知识
  • 原文地址:https://www.cnblogs.com/duoyan/p/15458785.html
Copyright © 2020-2023  润新知