java 将map中的object转换成bean实体

java 将map中的object转换成bean实体


引用阿里的fastjson

maven:

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>fastjson</artifactId>

<version>1.2.75</version>

</dependency>


import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.TypeReference;


代码示例:

public boolean saveSaleInfo(Map<String, Object> mapParams) {
        GySaleReportH gySaleReportHSaveInfo = new GySaleReportH();
        try {
            gySaleReportHSaveInfo=JSON.parseObject(JSON.toJSONString(mapParams.get("gySaleReportH")), new TypeReference<GySaleReportH>(){});
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.baseMapper.insert(gySaleReportHSaveInfo);
        return false;
    }


qrcode