json 字符串转换为Object实体数组
来源:互联网 发布:sqlserver读写分离 编辑:程序博客网 时间:2024/06/09 21:11
package com.dtdream.csr.manager.baseapi.common;import com.dtdream.csr.api.manager.indep.entity.IndepDtCenters;import com.dtdream.csr.api.manager.indep.entity.IndepDtcenterConf;import com.dtdream.csr.api.util.FileApi;import com.dtdream.csr.manager.dao.BaseDtcenterConfigDao;import com.dtdream.csr.manager.dao.BaseDtcenterRegionItemDao;import com.dtdream.csr.manager.entity.BaseDtcenterConfig;import com.dtdream.csr.manager.entity.BaseDtcenterRegionItem;import com.fasterxml.jackson.databind.ObjectMapper;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.inject.Inject;import javax.inject.Singleton;import javax.persistence.criteria.CriteriaBuilder;/** * Created by liucc on 17-6-19. */@Singletonpublic class DtcenterManager { private Logger logger = LoggerFactory.getLogger(DtcenterManager.class); @Inject private BaseDtcenterConfigDao baseDtcenterConfigDao; @Inject BaseDtcenterRegionItemDao baseDtcenterRegionItemDao; private static Map<String,IndepDtcenterConf> dtcenterConfMap = new HashMap<String, IndepDtcenterConf>(); public Map<String,IndepDtcenterConf> getDtcenterConfMap (){ return dtcenterConfMap; } public void registerDtcenter() { registerDtcenterConfig(); registerDtceterRegions(); } public void registerDtcenterConfig() { ObjectMapper objectMapper = new ObjectMapper(); try { File file = new File(FileApi.COM_DTDREAM_CSR_BASE); String tempString = FileApi.readContent(file,"UTF-8"); IndepDtCenters indepDtCenterList = objectMapper.readValue(tempString, IndepDtCenters.class); List<IndepDtcenterConf> confList = indepDtCenterList.getDtCenterConfList(); if(confList.size() == 0) { logger.error("DtcenterManager: Dtcenter is null"); return; } for (IndepDtcenterConf conf : confList) { if(dtcenterConfMap.get(conf.getId()) == null) { dtcenterConfMap.put(conf.getId(),conf); BaseDtcenterConfig baseConfig = baseDtcenterConfigDao.get(conf.getId()); if(baseConfig == null) { /*将Center的信息保存到数据库*/ baseConfig = new BaseDtcenterConfig(); baseConfig.setId(conf.getId()); baseConfig.setName(conf.getName()); baseConfig.setAccessKeyId(conf.getAccessKeyId()); baseConfig.setAccessKeySecret(conf.getAccessKeySecret()); baseConfig.setEndPoint(conf.getEndPoint()); baseDtcenterConfigDao.create(baseConfig); } } } } catch (IOException e) { e.printStackTrace(); } } public void registerDtceterRegions() { File file = new File("etc/com.dtdream.csr.region.json"); try { String tempString = FileApi.readContent(file,"UTF-8"); JSONObject json = JSONObject.fromObject(tempString); JSONArray jsonArray = json.getJSONArray("regions"); for (int i = 0; i < jsonArray.size(); i++) { JSONObject object = (JSONObject)jsonArray.get(i); BaseDtcenterRegionItem item = (BaseDtcenterRegionItem) JSONObject.toBean(object,BaseDtcenterRegionItem.class); BaseDtcenterRegionItem baseDtcenterRegion = baseDtcenterRegionItemDao.get(item.getRegionId()); if(jsonArray != null && baseDtcenterRegion == null) { baseDtcenterRegionItemDao.create(item); } } } catch (IOException e) { e.printStackTrace(); } }}
阅读全文
0 0
- json 字符串转换为Object实体数组
- Object转换为JSON格式字符串
- json字符串转换为object对象
- java 后台使用gson 将json字符串转换为List<Map<String,object>> 数组
- 如何将EntityFramework实体类转换为JSON字符串
- 将json字符串转换为实体类对象
- 将数组转换为json格式字符串
- Json格式字符串转换为数组
- 将数据模型(数组)转换为json字符串
- JS中json字符串转换为数组
- 把二维数组转换为json字符串
- json字符串转换为对象,json字符串中含数组
- javascript 将object转换为字符串JSON.stringify
- json转换时间类型的字符串为object-小心
- 将基于spring的json字符串转换为Object对象
- 字符串数组类型的object,如何转换为string[],
- java将JSON字符串转换为实体类对象,基于net.sf.json实现
- json之将json格式字符串数据转换为实体类.
- plugman创建自定义cordova插件
- 学习MaterialDesign和换肤
- $.ajax()方法详解
- FreeMarker入门
- 作为产品经理,你真的有数据 sense 吗?
- json 字符串转换为Object实体数组
- App测试中需要考虑网络因素的测试点
- 单例模式的7中写法
- windows网络编程(九)——IOCP+多线程实现简单的聊天(windows服务器端 windows客户端)
- 面试官提出的问题
- Library not found
- Android IntentService的使用
- 在线预览Office(可另存图片)
- 图片旋转工具类(分为:顺时针旋转90度、逆时针旋转90度、旋转180度、水平旋转、垂直旋转)