#数据导入

##文档整理

通用导入客户端

https://open.hand-china.com/hzero-docs/v1.3/zh/docs/service/import/import/

开放平台

https://open.hand-china.com/document-center/doc/component/174/10206?doc_id=133475&doc_code=3374#%E4%BD%BF%E7%94%A8%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF%E7%AE%A1%E7%90%86

https://open.hand-china.com/community/detail/625534031399882752#3.%20%20%20%20%20%20%20%E8%B0%83%E7%94%A8%E4%BB%8E%E4%B8%B4%E6%97%B6%E8%A1%A8%E5%AF%BC%E5%85%A5%E6%AD%A3%E5%BC%8F%E8%A1%A8%E6%8E%A5%E5%8F%A3

##客户端配置









##自定义参数及swagger测试

// 获取自定义参数
Map<String, Object> args = getArgs(); Long contractId = Long.parseLong(args.get(CONTRACTID).toString());
Long tenantId = Long.parseLong(args.get(TENANTID).toString());
String uuid = args.get(UUID).toString();
String typeCode = args.get(TYPE_CODE).toString();





##代码示例

application配置

hzero:
scheduler:
executor-code: HFLE_EXECUTOR
upload-log: false
import:
init-table: true
transactionControl: true
batchSize: 10000
lov:
value:
enabled: true
sql:
enabled: true
export:
# 默认请求模式,允许的值 SYNC ASYNC,默认null
# 默认请求模式设置为同步,则所有调用均为同步调用;默认请求模式设置为异步,则所有调用均为异步调用
# 当defaultRequestMode="ASYNC" && enableAsync=false时,服务会启动报错
default-request-mode:
# 是否开启异步,默认为false
enable-async: true
# 异步阈值,若导出的数据总量超过该阈值,强制执行异步导出
async-threshold:
# 默认最大sheet数,默认值5
single-excel-max-sheet-num: 5
# 默认sheet页最大行数,默认值1000000
single-sheet-max-row: 1000000
# 异步线程池核心线程数
core-pool-size: 3
# 异步线程池最大线程数
maximum-pool-size: 10
# 异步线程池线存活时间
keep-alive-time: 0
# 异步线程池线等待队列大小
queue-size:
# # 异步线程池线程名称
async-thread-name: async-export-executor

数据校验

package com.inja.mdm.app.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.inja.mdm.domain.entity.MdmMdGoodsReport;
import com.inja.mdm.domain.lov.MdmDataStatus;
import com.inja.mdm.domain.repository.MdmRepository;
import com.inja.mdm.domain.repository.UnitRepository;
import com.inja.mdm.domain.vo.MdmMdGoodsReportVO;
import io.choerodon.core.oauth.DetailsHelper;
import org.hzero.boot.imported.app.service.ValidatorHandler;
import org.hzero.boot.imported.infra.validator.annotation.ImportValidator;
import org.hzero.boot.imported.infra.validator.annotation.ImportValidators;
import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException;
import java.util.List; /**
* description
*
* @author Lenovo-pc 2021/11/05 14:42
*/
@ImportValidators({
@ImportValidator(templateCode = "MDM_MD_GOODS")
})
public class ImportValidatorMdmGoodsReportVO extends ValidatorHandler {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private UnitRepository unitRepository; @Autowired
private MdmRepository<MdmMdGoodsReport> mdmMdGoodsReportRepository; @Override
public boolean validate(String data) {
MdmMdGoodsReportVO mdmMdGoodsReportVO = new MdmMdGoodsReportVO();
MdmMdGoodsReport optional = new MdmMdGoodsReport();
final Long tenantId = DetailsHelper.getUserDetails().getTenantId(); try {
mdmMdGoodsReportVO = objectMapper.readValue(data, MdmMdGoodsReportVO.class);
} catch (IOException e) {
e.printStackTrace();
} //新增、编辑数据校验
if(mdmMdGoodsReportVO.getGoodsCode() == null){
//新增
optional.setTenantId(tenantId);
optional.setGoodsName(mdmMdGoodsReportVO.getGoodsName());
optional.setDeleteFlag("N");
String repeatCheck = null;
if (mdmMdGoodsReportVO.getModel() != null) {
repeatCheck = mdmMdGoodsReportVO.getGoodsName() + "+" + mdmMdGoodsReportVO.getGoodsSpec() + "+" + mdmMdGoodsReportVO.getModel() + "+" + mdmMdGoodsReportVO.getUnitIdMeaning();
} else if (mdmMdGoodsReportVO.getModel() == null) {
repeatCheck = mdmMdGoodsReportVO.getGoodsName() + "+" + mdmMdGoodsReportVO.getGoodsSpec() + "+" + mdmMdGoodsReportVO.getUnitIdMeaning();
}
optional.setRepeatCheck(repeatCheck);
MdmMdGoodsReport tempMdm = mdmMdGoodsReportRepository.selectOne(optional);
if(tempMdm != null){
getContext().addErrorMsg("这条数据已经存在");
return false;
}
return true;
} else {
//编辑
optional.setGoodsCode(mdmMdGoodsReportVO.getGoodsCode());
MdmMdGoodsReport tempMdm = mdmMdGoodsReportRepository.selectOne(optional);
if(tempMdm == null){
getContext().addErrorMsg("这条待编辑的数据不存在");
return false;
}
String status = tempMdm.getStatus();
if(!status.equals(MdmDataStatus.UNSUBMITTED.getValue())
&& !status.equals(MdmDataStatus.UNAPPROVE.getValue())){
getContext().addErrorMsg("状态有误这条数据不能更新");
return false;
}
//校验长描述
String repeatCheck = null;
if (mdmMdGoodsReportVO.getModel() != null) {
repeatCheck = mdmMdGoodsReportVO.getGoodsName() + "+" + mdmMdGoodsReportVO.getGoodsSpec() + "+" + mdmMdGoodsReportVO.getModel() + "+" + mdmMdGoodsReportVO.getUnitIdMeaning();
} else if (mdmMdGoodsReportVO.getModel() == null) {
repeatCheck = mdmMdGoodsReportVO.getGoodsName() + "+" + mdmMdGoodsReportVO.getGoodsSpec() + "+" + mdmMdGoodsReportVO.getUnitIdMeaning();
}
optional.setRepeatCheck(repeatCheck);
optional.setGoodsCode(null);
List<MdmMdGoodsReport> tempMdmCheck = mdmMdGoodsReportRepository.select(optional);
if (tempMdmCheck.size() == 1 && !tempMdmCheck.get(0).getGoodsCode().equals(mdmMdGoodsReportVO.getGoodsCode())) {
getContext().addErrorMsg("长描述重复不能更新");
return false;
}
return true;
}
}
}

数据导入

package com.inja.mdm.app.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.inja.mdm.app.service.MdmMdGoodsReportVOService;
import com.inja.mdm.domain.entity.*;
import com.inja.mdm.domain.lov.MdmDataStatus;
import com.inja.mdm.domain.repository.*;
import com.inja.mdm.domain.vo.MdmMdGoodsReportVO;
import com.inja.mdm.infra.repository.impl.PackagingTypeRepositoryImpl;
import io.choerodon.core.exception.CommonException;
import io.choerodon.core.oauth.DetailsHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.hzero.boot.imported.app.service.BatchImportHandler;
import org.hzero.boot.imported.infra.validator.annotation.ImportService;
import org.hzero.boot.platform.code.builder.CodeRuleBuilder;
import org.hzero.core.base.BaseConstants;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors; /**
* 商品提报表应用服务默认实现
*
* @author cmj 2021-11-01 09:26:40
* @Autowired private CodeRuleBuilder codeRuleBuilder;
* <p>
* private ObjectM
*/
@ImportService(templateCode = "MDM_MD_GOODS")
@Service
public class MdmMdGoodsReportVOServiceImpl extends BatchImportHandler implements MdmMdGoodsReportVOService { @Autowired
private MdmRepository<MdmMdGoodsReport> mdmGoodsReportRepository;
@Autowired
private UnitRepository unitRepository;
@Autowired
private MaterialClassRepository materialClassRepository;
@Autowired
private TranpricetypeRepository tranpricetypeRepository;
@Autowired
private TaxtypeRepository taxtypeRepository;
@Autowired
private CountryOfOriginRepository countryOfOriginRepository;
@Autowired
private NetContentUnitRepository netContentUnitRepository;
@Autowired
private PackagingTypeRepositoryImpl packagingTypeRepository;
@Autowired
private BrandRepository brandRepository; private ObjectMapper objectMapper; public MdmMdGoodsReportVOServiceImpl(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
} @Autowired
private CodeRuleBuilder codeRuleBuilder; @Override
public Boolean doImport(List<String> data) {
String voStr = BaseConstants.Symbol.LEFT_MIDDLE_BRACE + StringUtils.join(data.toArray(), BaseConstants.Symbol.COMMA)
+ BaseConstants.Symbol.RIGHT_MIDDLE_BRACE;
List<MdmMdGoodsReportVO> MdmMdGoodsReportVOs = null; try {
MdmMdGoodsReportVOs = objectMapper.readValue(voStr, objectMapper.getTypeFactory().constructParametricType(List.class, MdmMdGoodsReportVO.class));
} catch (IOException e) {
e.printStackTrace();
} final Long tenantId = DetailsHelper.getUserDetails().getTenantId(); List<MdmMdGoodsReportVO> insertMdmMdGoodsReportVOs = MdmMdGoodsReportVOs.stream()
.filter(T -> T.getGoodsCode() == null)
.collect(Collectors.toList());
List<MdmMdGoodsReportVO> updateMdmMdGoodsReportVOs = MdmMdGoodsReportVOs.stream()
.filter(T -> T.getGoodsCode() != null)
.collect(Collectors.toList()); //新增
if (!insertMdmMdGoodsReportVOs.isEmpty()) {
insertMdmMdGoodsReportVOs.forEach(T -> {
MdmMdGoodsReport mdmMdGoodsReport = new MdmMdGoodsReport();
BeanUtils.copyProperties(T, mdmMdGoodsReport);
mdmMdGoodsReport.setStatus(MdmDataStatus.UNSUBMITTED.getValue());
mdmMdGoodsReport.setTenantId(tenantId);
mdmMdGoodsReport.setDeleteFlag("N");
mdmMdGoodsReport.setGoodsCode(this.codeRuleBuilder.generateCode("MDM.BF.GOODS.EDIT", null));
// 查询商品分类(取物料四级分类)
if (null != T.getGoodClassCodeMeaning()) {
MaterialClass tempMaterialClass = new MaterialClass();
tempMaterialClass.setLevel("4");
tempMaterialClass.setMaterialClassCode(T.getGoodClassCodeMeaning());
List<MaterialClass> materialClass = materialClassRepository.select(tempMaterialClass);
if (materialClass.isEmpty()) {
throw new CommonException("error.mdm.goods.materialclassnotexist");
}
mdmMdGoodsReport.setGoodClassCode(materialClass.get(0).getMaterialClassCode());
}
// 查询计量单位
if (null == T.getUnitIdMeaning()) {
throw new CommonException("error.mdm.goods.unitnotexist");
}
Unit tempUnit = new Unit();
tempUnit.setUnitName(T.getUnitIdMeaning());
List<Unit> unit = unitRepository.select(tempUnit);
if (unit.isEmpty()) {
throw new CommonException("error.mdm.goods.unitnotexist");
}
mdmMdGoodsReport.setUnitId(unit.get(0).getUnitId());
// 查询运输计价类别
if (null == T.getTranpricetypeCodeMeaning()) {
throw new CommonException("error.mdm.goods.tranpricetypenotexist");
}
Tranpricetype tempTranpritype = new Tranpricetype();
tempTranpritype.setTranpricetypeName(T.getTranpricetypeCodeMeaning());
List<Tranpricetype> tranpricetype = tranpricetypeRepository.select(tempTranpritype);
if (tranpricetype.isEmpty()) {
throw new CommonException("error.mdm.goods.tranpricetypenotexist");
}
mdmMdGoodsReport.setTranpricetypeCode(tranpricetype.get(0).getTranpricetypeCode());
// 查询物料税类
if (null == T.getMaterialTaxIdMeaning()) {
throw new CommonException("error.mdm.goods.taxtypenotexist");
}
Taxtype tempTaxtype = new Taxtype();
tempTaxtype.setTaxtypeName(T.getMaterialTaxIdMeaning());
List<Taxtype> taxtype = taxtypeRepository.select(tempTaxtype);
if (taxtype.isEmpty()) {
throw new CommonException("error.mdm.goods.taxtypenotexist");
}
mdmMdGoodsReport.setMaterialTaxId(taxtype.get(0).getTaxtypeId());
// 查询品牌名称
if (null == T.getBrandIdMeaning()) {
throw new CommonException("error.mdm.goods.brandnotexist");
}
Brand tempBrand = new Brand();
tempBrand.setBrandName(T.getBrandIdMeaning());
List<Brand> brand = brandRepository.select(tempBrand);
if (brand.isEmpty()) {
throw new CommonException("error.mdm.goods.brandnotexist");
}
mdmMdGoodsReport.setBrandId(brand.get(0).getBrandId());
// 查询原产国
if (null != T.getOriginCountryIdMeaning()) {
CountryOfOrigin tempCountryOfOrigin = new CountryOfOrigin();
tempCountryOfOrigin.setCountryOfOriginName(T.getOriginCountryIdMeaning());
List<CountryOfOrigin> countryOfOrigin = countryOfOriginRepository.select(tempCountryOfOrigin);
if (countryOfOrigin.isEmpty()) {
throw new CommonException("error.mdm.goods.countryoforiginnotexist");
}
mdmMdGoodsReport.setOriginCountryId(countryOfOrigin.get(0).getCountryOfOriginId());
}
// 查询净含量单位
if (null != T.getNetContentUnitIdMeaning()) {
NetContentUnit tempNetContentUnit = new NetContentUnit();
tempNetContentUnit.setNetContentUnitName(T.getNetContentUnitIdMeaning());
List<NetContentUnit> netContentUnit = netContentUnitRepository.select(tempNetContentUnit);
if (netContentUnit.isEmpty()) {
throw new CommonException("error.mdm.goods.netcontentunitnotexist");
}
mdmMdGoodsReport.setNetContentUnitId(netContentUnit.get(0).getNetContentUnitId());
}
// 查询单品包装类型
if (null != T.getEachPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getEachPackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setEachPackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 查询中包包装类型
if (null != T.getPackPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getPackPackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setEachPackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 查询大包包装类型
if (null != T.getPackPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getCasePackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setCasePackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 商品长描述
String repeatCheck = null;
if (T.getModel() != null) {
repeatCheck = T.getGoodsName() + "+" + T.getGoodsSpec() + "+" + T.getModel() + "+" + T.getUnitIdMeaning();
} else if (T.getModel() == null) {
repeatCheck = T.getGoodsName() + "+" + T.getGoodsSpec() + "+" + T.getUnitIdMeaning();
}
mdmMdGoodsReport.setRepeatCheck(repeatCheck);
// 插入数据
mdmGoodsReportRepository.insertSelective(mdmMdGoodsReport);
});
} //编辑
if (!updateMdmMdGoodsReportVOs.isEmpty()) {
updateMdmMdGoodsReportVOs.forEach(T -> {
MdmMdGoodsReport tempMdmMdGoodsReport = new MdmMdGoodsReport();
tempMdmMdGoodsReport.setGoodsCode(T.getGoodsCode());
List<MdmMdGoodsReport> mdmMdGoodsReportList = mdmGoodsReportRepository.select(tempMdmMdGoodsReport);
MdmMdGoodsReport mdmMdGoodsReport = mdmMdGoodsReportList.get(0);
Long id = mdmMdGoodsReport.getGoodsId();
BeanUtils.copyProperties(T, mdmMdGoodsReport);
mdmMdGoodsReport.setGoodsId(id);
// 查询商品分类(取物料四级分类)
if (null != T.getGoodClassCodeMeaning()) {
MaterialClass tempMaterialClass = new MaterialClass();
tempMaterialClass.setLevel("4");
tempMaterialClass.setMaterialClassName(T.getGoodClassCodeMeaning());
List<MaterialClass> materialClass = materialClassRepository.select(tempMaterialClass);
if (materialClass.isEmpty()) {
throw new CommonException("error.mdm.goods.materialclassnotexist");
}
mdmMdGoodsReport.setGoodClassCode(materialClass.get(0).getMaterialClassCode());
}
// 查询计量单位
if (null == T.getUnitIdMeaning()) {
throw new CommonException("error.mdm.goods.unitnotexist");
}
Unit tempUnit = new Unit();
tempUnit.setUnitName(T.getUnitIdMeaning());
List<Unit> unit = unitRepository.select(tempUnit);
if (unit.isEmpty()) {
throw new CommonException("error.mdm.goods.unitnotexist");
}
mdmMdGoodsReport.setUnitId(unit.get(0).getUnitId());
// 查询运输计价类别
if (null == T.getTranpricetypeCodeMeaning()) {
throw new CommonException("error.mdm.goods.tranpricetypenotexist");
}
Tranpricetype tempTranpritype = new Tranpricetype();
tempTranpritype.setTranpricetypeName(T.getTranpricetypeCodeMeaning());
List<Tranpricetype> tranpricetype = tranpricetypeRepository.select(tempTranpritype);
if (tranpricetype.isEmpty()) {
throw new CommonException("error.mdm.goods.tranpricetypenotexist");
}
mdmMdGoodsReport.setTranpricetypeCode(tranpricetype.get(0).getTranpricetypeCode());
// 查询物料税类
if (null == T.getMaterialTaxIdMeaning()) {
throw new CommonException("error.mdm.goods.taxtypenotexist");
}
Taxtype tempTaxtype = new Taxtype();
tempTaxtype.setTaxtypeName(T.getMaterialTaxIdMeaning());
List<Taxtype> taxtype = taxtypeRepository.select(tempTaxtype);
if (taxtype.isEmpty()) {
throw new CommonException("error.mdm.goods.taxtypenotexist");
}
mdmMdGoodsReport.setMaterialTaxId(taxtype.get(0).getTaxtypeId());
// 查询品牌名称
if (null != T.getBrandIdMeaning()) {
Brand tempBrand = new Brand();
tempBrand.setBrandName(T.getBrandIdMeaning());
List<Brand> brand = brandRepository.select(tempBrand);
if (brand.isEmpty()) {
throw new CommonException("error.mdm.goods.brandnotexist");
}
mdmMdGoodsReport.setBrandId(brand.get(0).getBrandId());
}
// 查询原产国
if (null != T.getOriginCountryIdMeaning()) {
CountryOfOrigin tempCountryOfOrigin = new CountryOfOrigin();
tempCountryOfOrigin.setCountryOfOriginName(T.getOriginCountryIdMeaning());
List<CountryOfOrigin> countryOfOrigin = countryOfOriginRepository.select(tempCountryOfOrigin);
if (countryOfOrigin.isEmpty()) {
throw new CommonException("error.mdm.goods.countryoforiginnotexist");
}
mdmMdGoodsReport.setOriginCountryId(countryOfOrigin.get(0).getCountryOfOriginId());
}
// 查询净含量单位
if (null != T.getNetContentUnitIdMeaning()) {
NetContentUnit tempNetContentUnit = new NetContentUnit();
tempNetContentUnit.setNetContentUnitName(T.getNetContentUnitIdMeaning());
List<NetContentUnit> netContentUnit = netContentUnitRepository.select(tempNetContentUnit);
if (netContentUnit.isEmpty()) {
throw new CommonException("error.mdm.goods.netcontentunitnotexist");
}
mdmMdGoodsReport.setNetContentUnitId(netContentUnit.get(0).getNetContentUnitId());
}
// 查询单品包装类型
if (null != T.getEachPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getEachPackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setEachPackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 查询中包包装类型
if (null != T.getPackPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getPackPackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setEachPackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 查询大包包装类型
if (null != T.getPackPackagingTypeIdMeaning()) {
PackagingType tempPackagingType = new PackagingType();
tempPackagingType.setPackagingTypeName(T.getCasePackagingTypeIdMeaning());
List<PackagingType> packagingType = packagingTypeRepository.select(tempPackagingType);
if (packagingType.isEmpty()) {
throw new CommonException("error.mdm.goods.packagingTypenotexist");
}
mdmMdGoodsReport.setCasePackagingTypeId(packagingType.get(0).getPackagingTypeId());
}
// 商品长描述
String repeatCheck = null;
if (T.getModel() != null) {
repeatCheck = T.getGoodsName() + "+" + T.getGoodsSpec() + "+" + T.getModel() + "+" + T.getUnitIdMeaning();
} else if (T.getModel() == null) {
repeatCheck = T.getGoodsName() + "+" + T.getGoodsSpec() + "+" + T.getUnitIdMeaning();
}
mdmMdGoodsReport.setRepeatCheck(repeatCheck);
// 插入数据
mdmGoodsReportRepository.updateByPrimaryKeySelective(mdmMdGoodsReport);
});
} return true;
} }

##对象序列化









https://blog.csdn.net/mingyuli/article/details/119455324

public class UserBase {

    /**
* 用户名
*/
private String userName; /**
* 年龄
*/
private Integer age; /**
* 增加时间
*/
private Date addTime; public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public Date getAddTime() {
return addTime;
} public void setAddTime(Date addTime) {
this.addTime = addTime;
}
} public class TestMain { public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
String json1 = "{\"userName\":\"小李飞刀\",\"age\":18,\"addTime\":1591851786568}";
String json2 = "[{\"userName\":\"小李飞刀\",\"age\":18,\"addTime\":123}, {\"userName\":\"小李飞刀2\",\"age\":182,\"addTime\":1234}]";
try {
//1、json字符串转为对象
UserBase userBase1 = objectMapper.readValue(json1, UserBase.class);
UserBase userBase2 = objectMapper.readValue(json1, new TypeReference<UserBase>(){});
System.out.println(userBase1.getUserName());
System.out.println(userBase2.getUserName()); //2、json转为map
Map<String,Object> map = objectMapper.readValue(json1, new TypeReference<Map<String,Object>>(){});
//map:{userName=小李飞刀, age=18, addTime=1591851786568}
System.out.println("map:" + map); //3、json转为list<bean>
//使用json1报错,此时需要数组/集合类型: Can not deserialize instance of TEst.UserBase[] out of START_OBJECT token
List<UserBase> lists = objectMapper.readValue(json2, new TypeReference<List<UserBase>>(){});
System.out.println(lists.get(0).getUserName()); //4、json转为数组
UserBase[] userBases = objectMapper.readValue(json1, new TypeReference<UserBase[]>(){});
System.out.println(userBases[0].getUserName()); //序列化
Map<String,String> map1 = Maps.newHashMap();
map1.put("name", "小李飞刀");
map1.put("sex", "男");
String json = objectMapper.writeValueAsString(map1);
System.out.println(json);
//反序列化
Map<String,String> maps = objectMapper.readValue(json,new TypeReference<Map<String,String>>(){});
System.out.println(maps.get("name"));
//反序列化
List<UserBase> listes = objectMapper.readValue(json,new TypeReference<List<UserBase>>(){});
System.out.println(listes.get(0).getUserName());
//反序列化
UserBase[] userBasess = objectMapper.readValue(json,new TypeReference<UserBase[]>(){});
System.out.println(userBasess[0].getUserName()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//法一
List<UserBase> userBases1 = objectMapper.readValue(json2, new TypeReference<List<UserBase>>(){});
//法二
JavaType javaType= objectMapper.getTypeFactory().constructCollectionType(List.class, UserBase.class);
List<UserBase> list2 = objectMapper.readValue(json1, javaType);
} catch (Exception e) {
e.printStackTrace();
}
}
}

【HZERO】数据导入的更多相关文章

  1. ITTC数据挖掘平台介绍(五) 数据导入导出向导和报告生成

    一. 前言 经过了一个多月的努力,软件系统又添加了不少新功能.这些功能包括非常实用的数据导入导出,对触摸进行优化的画布和画笔工具,以及对一些智能分析的报告生成模块等.进一步加强了平台系统级的功能. 马 ...

  2. FineReport实现EXCEL数据导入自由报表

    在制作填报报表的时候,对于空白填报表,常常导出为Excel,派发给各部门人员填写后上交.如何能避免手动输入,直接将Excel中的数据导入到填报表中提交入库呢? 这里以一个简单的员工信息填报示例进行介绍 ...

  3. Execl数据导入sql server方法

    在日常的程序开发过程中,很多情况下,用户单位给予开发人员的数据往往是execl或者是access数据,如何把这些数据转为企业级是数据库数据呢,下面就利用sqlserver自带的功能来完成此项任务. 首 ...

  4. kettle将Excel数据导入oracle

    导读 Excel数据导入Oracle数据库的方法: 1.使用PL SQL 工具附带的功能,效率比较低 可参考这篇文章的介绍:http://www.2cto.com/database/201212/17 ...

  5. [Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!

    引言 项目中常用到将数据导入Excel,将Excel中的数据导入数据库的功能,曾经也查找过相关的内容,将曾经用过的方案总结一下. 方案一 NPOI NPOI 是 POI 项目的 .NET 版本.POI ...

  6. sqlserver 中数据导入到mysql中的方法以及注意事项

    数据导入从sql server 到mysql (将数据以文本格式从sqlserver中导出,注意编码格式,再将文本文件导入mysql中): 1.若从slqserver中导出的表中不包含中文采用: bc ...

  7. 数据分析(7):pandas介绍和数据导入和导出

    前言 Numpy Numpy是科学计算的基础包,对数组级的运算支持较好 pandas pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数.pandas兼具Numpy高性能的数组计 ...

  8. MySQL学习笔记十一:数据导入与导出

    数据导入 1.mysqlimport命令行导入数据 在使用mysqlimport命令导入数据时,数据来源文件名要和目标表一致,不想改文件名的话,可以复制一份创建临时文件,示例如下. 建立一个文本use ...

  9. geotrellis使用(十二)再记录一次惨痛的伪BUG调试经历(数据导入以及读取瓦片)

    Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 BUG还原 查找BUG 解决方案 总结 后记 一.前 ...

  10. geotrellis使用(十三)数据导入BUG解决方案说明

    Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 BUG说明 解决方案 总结 一.前言         ...

随机推荐

  1. jdk所有版本-自留收藏

    链接:https://pan.baidu.com/s/1NDbEAEbKeh8xFzjEwB8aLg 提取码:0000

  2. 文心一言 VS 讯飞星火 VS chatgpt (154)-- 算法导论12.3 1题

    一.用go语言,给出 TREE-INSERT 过程的一个递归版本. 文心一言,代码不能运行: 下面是用 Go 语言实现一个递归版本的 TREE-INSERT 过程的代码: package main i ...

  3. AtomicArray

    AtomicInteger ai = new AtomicInteger(1); //1.获取值 System.out.println("ai.get = "+ai.get()); ...

  4. 5个免费、跨平台的SQLite数据库可视化工具

    前言 SQLite是一个轻量级的嵌入式关系型数据库,目前最新的版本是 SQLite3.今天推荐5个实用的SQLite数据库可视化工具(GUI),帮助大家更好的管理SQLite数据库. 什么是SQLit ...

  5. PTA 函数与递归部分题目讲解及思路

    7-1 判断素数 题目分析 题目输入n个数,判断其是否为质数 对于判断质数,只需要满足从2开始遍历的每一个数一直到√n均无法被n整除即可 关于为什么只要到√n呢? 因为n = √n * √n,因此其最 ...

  6. NetSuite 开发日记:创建 Transfer(转账单)

    经测试,截止到 2022.12.26,Transfer 只能使用 Client 脚本创建,使用服务端脚本创建报错:ReferenceError: "document" is not ...

  7. 服务网格 Service Mesh

    什么是服务网格? 服务网格是一个软件层,用于处理应用程序中服务之间的所有通信.该层由容器化微服务组成.随着应用程序的扩展和微服务数量的增加,监控服务的性能变得越来越困难.为了管理服务之间的连接,服务网 ...

  8. 前端 Git 使用约定

    前端 Git 使用约定 背景 开发前端项目,有以下困惑: 使用哪个分支开发,哪个分支发布 修复线上bug的流程是什么,如何避免修复完了下次却又出现了 cms分支有十多个,是否都有用 如何快速找到之前某 ...

  9. zabbix_agent配置文件

    agent常用参数 : [root@jqebsdb zabbix]# cat zabbix_agentd.conf  | grep -v ^$ | grep -v ^# PidFile=/var/ru ...

  10. IDEA Edit Configuration解决隐藏了不见了

    IDEA Edit Configuration解决隐藏了不见了 IDEA Edit Configuration解决隐藏了不见了,我的IDEA版本是2020.3.4,某天按了哪个快捷键导致不见了.按Al ...