2018-11-28 13:33:46 432浏览
今天扣丁学堂Java培训老师给大家介绍一下关于JAVA工作流优雅实现的方式详解。首先大家肯定用过责任链模式,也用过模板模式实现类工作流的方式,但是对比这个工具,逊色不少,不卖关子了,就是ApacheCommonsChain,它是Command模式与责任链模式的综合体。1、ApacheCommonsChain中的角色有:chain、context、command。
<dependency>
<groupId>commons-chain</groupId>
<artifactId>commons-chain</artifactId>
<version>1.2</version>
</dependency>
/**
* 退商旅卡Cash
* Created by 一代天骄 on 2018/7/1.
*/
@Slf4j
public class RefundBusinessCardCommand implements Command{
public boolean execute(Context context) throws Exception {
RefundContext refundContext = (RefundContext) context;
log.info("orderId:{} 退款开始,第一步:退商旅卡,金额:{}",refundContext.getOrderId(),"10");
return false;
}
}
/**
* 退现金
* Created by 一代天骄 on 2018/7/1.
*/
@Slf4j
public class RefundCashCommand implements Command {
public boolean execute(Context context) throws Exception {
RefundContext refundContext = (RefundContext) context;
log.info("orderId:{}退款开始,第二步:退现金,金额:{}",refundContext.getOrderId(),"5");
return false;
}
}
/**
* 退优惠券
* Created by 一代天骄 on 2018/7/1.
*/
@Slf4j
public class RefundPromotionCommand implements Command{
public boolean execute(Context context) throws Exception {
RefundContext refundContext = (RefundContext) context;
log.info("orderId:{} 退款开始,第二步:退优惠券,金额:{}",refundContext.getOrderId(),"20");
return false;
}
}
/**
* Created by 一代天骄 on 2018/7/1.
*/
@Data
public class RefundContext extends ContextBase {
/**
* 订单号
*/
private Integer orderId;
}
/**
*
* 退票的工作流实现
* Created by 一代天骄 on 2018/7/1.
*/
public class RefundTicketChain extends ChainBase {
public void init() {
//退商旅卡
this.addCommand(new RefundBusinessCardCommand());
//退现金
this.addCommand(new RefundCashCommand());
//退优惠券
this.addCommand(new RefundPromotionCommand());
}
public static void main(String[] args) throws Exception {
RefundTicketChain refundTicketChain = new RefundTicketChain();
refundTicketChain.init();
RefundContext context = new RefundContext();
context.setOrderId(1621940242);
refundTicketChain.execute(context);
}
}
以上就是关于扣丁学堂Java培训详解JAVA工作流的优雅实现的方式详解,希望对大家的学习有所帮助,请关注扣丁学堂Java培训官网、微信等平台,扣丁学堂IT职业在线学习教育平台为您提供权威的Java视频教程供大家学习,Java培训后的前景无限,行业薪资和未来的发展会越来越好的。扣丁学堂Java技术交流群:670348138。
【关注微信公众号获取更多学习资料】