java 向Redis中存放数据 List<Device>转String

/**
* redis服务
*/
@Autowired
private RedisService redisService;

 

 

//创建 Device  对象

Device no = new Device();

//设置属性

no.setDeviceNo("Ubibot1");
no.setCompanyId(10);
no.setGroupId(1);

// 创建异常设备集合
List<Device> deviceError = new ArrayList<Device>();

//在集合中放入no 对象

deviceError.add(no);

//如果集合有值

if(deviceError.size() > 0) {

  // 异常设备的json数组,把list转换成json数组
  JSONArray jsonArray = JSONObject.parseArray(JSON.toJSONString(deviceError));

  //把json数组转换成String类型
  String json = jsonArray.toJSONString();

  // 将错误装置JSON数组放入redis中
  redisService.set(RedisKey.CULTIVATION_RECORD_ERROR, json);

}

 

posted @ 2020-03-18 14:58  程程111  阅读(5245)  评论(0编辑  收藏  举报