当前位置: 首页 > news >正文

检察院网站建设自查网页制作与网站建设初学者必看教程

检察院网站建设自查,网页制作与网站建设初学者必看教程,动漫设计与制作主修课程有哪些,网站访客统计代码使用 spring-statemachine 状态机持久化时#xff0c;可以通过内存、spring-statemachine-redis 或 spring-statemachine-data-jpa 现有方式持久化处理。 因项目审核操作记录频繁#xff0c;数据量大#xff0c;使用 内存 或 spring-statemachine-redis 模式不可取#xf…使用 spring-statemachine 状态机持久化时可以通过内存、spring-statemachine-redis 或 spring-statemachine-data-jpa 现有方式持久化处理。 因项目审核操作记录频繁数据量大使用 内存 或 spring-statemachine-redis 模式不可取而项目使用的是 MyBatis使用 spring-statemachine-data-jpa 也不合适需要自定义实现简述步骤如下 一、引入依赖 !--状态机--dependencygroupIdorg.springframework.statemachine/groupIdartifactIdspring-statemachine-starter/artifactIdversion2.2.3.RELEASE/version/dependencydependencygroupIdorg.springframework.statemachine/groupIdartifactIdspring-statemachine-kryo/artifactIdversion1.2.14.RELEASE/version/dependency 二、创建持久化记录存储表 CREATE TABLE state_machine_context (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 自增主键,machine_type VARCHAR (32) DEFAULT COMMENT 状态机类型,machine_id VARCHAR (36) DEFAULT COMMENT 状态机ID,machine_data TINYBLOB COMMENT 状态机数据,machine_state VARCHAR (32) DEFAULT COMMENT 状态机状态,machine_event VARCHAR (36) DEFAULT COMMENT 状态机事件,create_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 创建时间,update_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 更新时间,PRIMARY KEY (id),KEY idx_machine_id (machine_id) ) ENGINE INNODB COMMENT 状态机上下文 关键字段说明  machine_type标记业务类型如订单业务、用户业务macheine_id业务数据ID如订单ID、用户IDmachine_data状态机二进制数据 其它字段可根据自己业务需求自定义 三、自定义持久化类即实现接口 StateMachinePersist import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import org.apache.commons.lang3.tuple.Pair; import org.springframework.messaging.MessageHeaders; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.StateMachinePersist; import org.springframework.statemachine.kryo.MessageHeadersSerializer; import org.springframework.statemachine.kryo.StateMachineContextSerializer; import org.springframework.statemachine.kryo.UUIDSerializer;import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Date; import java.util.Objects; import java.util.Optional; import java.util.UUID;/*** author songjianyong*/ public class CustomStateMachinePersistS, E implements StateMachinePersistS, E, PairString, String {private static final ThreadLocalKryo KRYO_THREAD_LOCAL ThreadLocal.withInitial(() - {Kryo kryo new Kryo();kryo.addDefaultSerializer(StateMachineContext.class, new StateMachineContextSerializer());kryo.addDefaultSerializer(MessageHeaders.class, new MessageHeadersSerializer());kryo.addDefaultSerializer(UUID.class, new UUIDSerializer());return kryo;});private byte[] serialize(StateMachineContextS, E context) {Kryo kryo KRYO_THREAD_LOCAL.get();ByteArrayOutputStream out new ByteArrayOutputStream();Output output new Output(out);kryo.writeObject(output, context);output.close();return out.toByteArray();}SuppressWarnings(unchecked)private StateMachineContextS, E deserialize(byte[] data) {if (data null || data.length 0) {return null;}Kryo kryo KRYO_THREAD_LOCAL.get();ByteArrayInputStream in new ByteArrayInputStream(data);Input input new Input(in);return kryo.readObject(input, StateMachineContext.class);}private final StateMachineContextDao stateMachineContextDao;public SongStateMachinePersist(StateMachineContextDao stateMachineContextDao) {this.stateMachineContextDao stateMachineContextDao;}Overridepublic void write(StateMachineContextS, E context, PairString, String pair) throws Exception {byte[] machineData serialize(context);String machineId pair.getKey();String machineType pair.getValue();StateMachineContextEntity stateMachineContexEntity stateMachinePersistDao.findByMachineIdAndMachineType(machineId, machineType);if (Objects.nonNull(stateMachineContexEntity)) {stateMachineContexEntity.setMachineData(machineData);stateMachineContexEntity.setMachineState(Optional.ofNullable(context.getState()).map(Objects::toString).orElse(stateMachineContexEntity.getMachineState()));stateMachineContexEntity.setMachineEvent(Optional.ofNullable(context.getEvent()).map(Objects::toString).orElse(stateMachineContexEntity.getMachineEvent()));stateMachineContexEntity.setUpdateDate(new Date());stateMachineContextDao.updateById(stateMachineContexEntity);return;}StateMachineContextEntity entity new StateMachineContextEntity();entity.setMachineId(machineId);entity.setMachineData(machineData);entity.setMachineType(machineType);entity.setMachineState(Optional.ofNullable(context.getState()).map(Objects::toString).orElse(null));entity.setMachineEvent(Optional.ofNullable(context.getEvent()).map(Objects::toString).orElse(null));stateMachineContextDao.save(entity);}Overridepublic StateMachineContextS, E read(PairString, String pair) throws Exception {String machineId pair.getKey();String machineType pair.getValue();StateMachineContextEntity stateMachineContexEntity stateMachineContextDao.findByMachineIdAndMachineType(machineId, machineType);if (Objects.isNull(stateMachineContexEntity)) {return null;}byte[] machineData stateMachineContexEntity.getMachineData();return deserialize(machineData);} }四、自定义状态机即继承类 AbstractStateMachinePersister import org.apache.commons.lang3.tuple.Pair; import org.springframework.statemachine.StateMachinePersist; import org.springframework.statemachine.persist.AbstractStateMachinePersister;/*** author songjianyong*/ public class CustomStateMachinePersisterS, E extends AbstractStateMachinePersisterS, E, PairString, String {public CustomStateMachinePersister(StateMachinePersistS, E, PairString, String stateMachinePersist) {super(stateMachinePersist);} } 五、使用自定义状态机 /*** 持久化到库中** return 数据库持久化状态机*/Bean(name customStateMachinePersister)public CustomStateMachinePersisterS, E customStateMachinePersister(StateMachineContextDao stateMachineContextDao) {CustomStateMachinePersistS, E customStateMachinePersist new CustomStateMachinePersist(stateMachineContextDao);return new CustomStateMachinePersister(customStateMachinePersist);} Resourceprivate StateMachinePersisterOrderStatus, OrderStatusChangeEvent, PairString, String pair customStateMachinePersister;
http://www.yutouwan.com/news/278804/

相关文章:

  • 广州网站制作费用湖南网站建设网站制作
  • 怎么在百度搜索到我的网站软件开发平台简介
  • 单页网站如何制作现在做网站到底需要多少钱
  • 钓鱼网站怎么做网站地图分析工具
  • 有哪个网站可以学做面条开面馆推广文案
  • 深圳做企业网站的公司推荐网站开发专业有什么工作
  • wordpress多站点会员注册网络平台运营计划方案
  • 学做网站教学百度网盘杭州鼎易科技做网站太坑
  • vs2013 手机网站开发给个网站好人有好报
  • wordpress建站主机建设广告联盟网站
  • 兴义做网站国外外贸平台有哪些
  • 上海 政务网站建设情况国外html响应式网站模板
  • 关于教育网站的策划书桂林论坛
  • 山河建设有限公司网站大连网站制作-中国互联
  • 网站设计连接数据库怎么做安全的小网站
  • 福州市建设工程材料价格管理系统网站西安网站挂标
  • 网站强制使用极速模式中国网络安全厂商排名
  • 建设网站专家平阳网站建设公司
  • 鞍山做网站的做网站搞友情链接
  • 制作网架厂家搜索引擎优化概述
  • 网上做效果图网站有哪些软件编程培训机构需要哪些证件
  • 做网站建设公司网易互客网站公司设计 网站首页
  • 怎么做外卖网站WordPress数字商城模板
  • 企业网站硬件建设方案这么做钓鱼网站
  • 杭州网站建设索q479185700遵义网站制作费用
  • 温州建设诚信评价网站公示android studio安装教程
  • 简述电子商务网站建设的基本流程重庆企业网站建设价格
  • 上饶网站建设企业免费公司网站怎么做
  • 做网站现在还行吗建立企业网站
  • 网站建设总经理岗位职责小程序游戏排行榜2022