2018-11-28 13:33:46 1209瀏覽
今天扣丁學堂Java培訓老師給大家介紹一下關(guān)于JAVA工作流優(yōu)雅實現(xiàn)的方式詳解。首先大家肯定用過責任鏈模式,也用過模板模式實現(xiàn)類工作流的方式,但是對比這個工具,遜色不少,不賣關(guān)子了,就是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; } }
/** * 退現(xiàn)金 * 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:{}退款開始,第二步:退現(xiàn)金,金額:{}",refundContext.getOrderId(),"5"); return false; } }
/** * 退優(yōu)惠券 * 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:{} 退款開始,第二步:退優(yōu)惠券,金額:{}",refundContext.getOrderId(),"20"); return false; } }
/** * Created by 一代天驕 on 2018/7/1. */ @Data public class RefundContext extends ContextBase { /** * 訂單號 */ private Integer orderId; }
/** * * 退票的工作流實現(xiàn) * Created by 一代天驕 on 2018/7/1. */ public class RefundTicketChain extends ChainBase { public void init() { //退商旅卡 this.addCommand(new RefundBusinessCardCommand()); //退現(xiàn)金 this.addCommand(new RefundCashCommand()); //退優(yōu)惠券 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); } }
以上就是關(guān)于扣丁學堂Java培訓詳解JAVA工作流的優(yōu)雅實現(xiàn)的方式詳解,希望對大家的學習有所幫助,請關(guān)注扣丁學堂Java培訓官網(wǎng)、微信等平臺,扣丁學堂IT職業(yè)在線學習教育平臺為您提供權(quán)威的Java視頻教程供大家學習,Java培訓后的前景無限,行業(yè)薪資和未來的發(fā)展會越來越好的??鄱W堂Java技術(shù)交流群:670348138。
【關(guān)注微信公眾號獲取更多學習資料】
查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>