• 存储字节类型


    public void updateDistributeSearchParams(final String id, final ArrayListsearchParamList) {
    String sql = " update ht_distribute_task set searchparamlist = ?  where id = ? ";
    this.getJdbcTemplate().execute(sql, new AbstractLobCreatingPreparedStatementCallback(this.defaultLobHandler) {
    @Override
    protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException {
           byte[] bytes = null;
           try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(searchParamList);
    oos.close();
    bytes = baos.toByteArray();
    baos.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    lobCreator.setBlobAsBytes(ps, 1, bytes);
    ps.setString(2, id);
    }
    });
    }


    public DistributeTask findDistributeTaskById(String id) {
    String sql = "select * from ht_distribute_task where id = ? ";
    List taskList = this.getJdbcTemplate().query(sql, new Object[]{id}, new DistributeTaskRowMapper());
    if(taskList.size() > 0) {
    DistributeTask t = taskList.get(0);
    return t;
    return null;
    }



    public class DistributeTaskRowMapper implements RowMapper {

    private Logger logger = LoggerFactory.getLogger(DistributeTaskRowMapper.class);

    private LobHandler defaultLobHandler;   
    @SuppressWarnings("unchecked")
    @Override
    public DistributeTask mapRow(ResultSet rs, int rowNum) throws SQLException {
    defaultLobHandler = SpringContextHolder.getBean("defaultLobHandler");
    DistributeTask task = new DistributeTask();
    task.setId(rs.getString("id"));
    task.setName(rs.getString("name"));
    task.setOperateReason(rs.getString("operatereason"));
    task.setTypeCode(rs.getInt("typecode"));
    task.setRuleCode(rs.getInt("rulecode"));
    task.setStatusCode(rs.getInt("statuscode"));
    task.setSuccessResourceOperateable(rs.getBoolean("successresourceoperateable"));
    task.setAsync(rs.getBoolean("async"));
    task.setSynCustomerIds(rs.getString("syncustomerids"));
    task.setSearchSql(rs.getString("searchsql"));
    task.setTargetCount(rs.getInt("targetcount"));
    task.setEffectCount(rs.getInt("effectcount"));
    task.setFinishCount(rs.getInt("finishcount"));
    task.setTimerTaskStartTime(rs.getString("timertaskstarttime"));
    task.setTimerTaskEndTime(rs.getString("timertaskendtime"));
    task.setCreateUserId(rs.getString("createuserid"));
    task.setCreateDate(rs.getTimestamp("createdate")); // 备注,这里千万不能用 rs.getDate() [返回的只有年月日]
    task.setEffectiveMilsec(rs.getLong("effectivemilsec"));
    task.setDurationMilsec(rs.getLong("durationmilsec"));
    task.setModifyDate(rs.getTimestamp("modifydate"));
    ArrayListsearchParamList = new ArrayList();
    try { // 处理二进制数据
    byte[] searchParamBytes = defaultLobHandler.getBlobAsBytes(rs, "searchparamlist");
    if(searchParamBytes != null) {
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(searchParamBytes));
    searchParamList = ((ArrayList) ois.readObject());
    ois.close();
    }
    } catch (Exception e) {
    logger.error("JIANGRH_查询分配任务时,对任务数据中的二进制信息进行包装出现异常--"+e.getMessage(), e);
    }
    task.setSearchParamList(searchParamList);
    return task;
    }
    }
  • 相关阅读:
    上传到dockerhub
    ILSpycmd 手册
    自制防丢纽扣:防airtag
    备忘:MIP算法
    Python学习笔记:select_dtypes选取指定数据类型的列
    Python学习笔记:LGB/XGB/CatBoost/NGB之安装
    Python学习笔记:dataframe行遍历之iterrows
    Python学习笔记:数据框dataframe列反转
    PHP获取汉字首字母并分组排序 何苦
    mysql 批量更新(插入)表字段 清洗数据 存储过程 何苦
  • 原文地址:https://www.cnblogs.com/kevin443/p/7726963.html
Copyright © 2020-2023  润新知