一、

1.

2.pizza-flow.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow
 3 http://www.springframework.org/schema/webflow/spring-webflow-2.3.xsd">
 4     <var name="order" class="com.springinaction.pizza.domain.Order" />
 5     <subflow-state id="identifyCustomer" subflow="pizza/customer">
 6         <output name="customer" value="order.customer" />
 7         <transition on="customerReady" to="buildOrder" />
 8     </subflow-state>
 9     <subflow-state id="buildOrder" subflow="pizza/order">
10         <input name="order" value="order" />
11         <transition on="orderCreated" to="takePayment" />
12     </subflow-state>
13     <subflow-state id="takePayment" subflow="pizza/payment">
14         <input name="order" value="order" />
15         <transition on="paymentTaken" to="saveOrder" />
16     </subflow-state>
17     <action-state id="saveOrder">
18         <evaluate expression="pizzaFlowActions.saveOrder(order)" />
19         <transition to="thankCustomer" />
20     </action-state>
21     <view-state id="thankCustomer">
22         <transition to="endState" />
23     </view-state>
24     <end-state id="endState" />
25     <global-transitions>
26         <transition on="cancel" to="endState" />
27     </global-transitions>
28 </flow>

或把信息全都写进order.customer里,就不用在cutomer flow中定义customer,最后要output customer

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <flow xmlns="http://www.springframework.org/schema/webflow"
 3   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4   xsi:schemaLocation="http://www.springframework.org/schema/webflow
 5   http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
 6
 7     <var name="order" class="com.springinaction.pizza.domain.Order"/>
 8
 9     <!-- Customer -->
10     <subflow-state id="customer" subflow="pizza/customer">
11       <input name="order" value="order"/>
12       <transition on="customerReady" to="order" />
13     </subflow-state>
14
15     <!-- Order -->
16     <subflow-state id="order" subflow="pizza/order">
17       <input name="order" value="order"/>
18       <transition on="orderCreated" to="payment" />
19     </subflow-state>
20
21     <!-- Payment -->
22     <subflow-state id="payment" subflow="pizza/payment">
23       <input name="order" value="order"/>
24       <transition on="paymentTaken" to="saveOrder"/>
25     </subflow-state>
26
27     <action-state id="saveOrder">
28         <evaluate expression="pizzaFlowActions.saveOrder(order)" />
29         <transition to="thankYou" />
30     </action-state>
31
32     <view-state id="thankYou">
33       <transition to="endState" />
34     </view-state>
35
36     <!-- End state -->
37     <end-state id="endState" />
38
39     <global-transitions>
40       <transition on="cancel" to="endState" />
41     </global-transitions>
42 </flow>

默认会从第一个state开始,也可以明确指定

1 <?xml version="1.0" encoding="UTF-8"?>
2 <flow xmlns="http://www.springframework.org/schema/webflow"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://www.springframework.org/schema/webflow
5 http://www.springframework.org/schema/webflow/spring-webflow-2.3.xsd"
6 start-state="identifyCustomer">
7 ...
8 </flow>

The first thing you see in the flow definition is the declaration of the order variable.Each time the flow starts, a new instance of Order is created. The Order class has properties for carrying all the information about an order, including the customer information, the list of pizzas ordered, and the payment details.

3.

 1 package com.springinaction.pizza.domain;
 2
 3 import java.io.Serializable;
 4 import java.util.ArrayList;
 5 import java.util.List;
 6
 7 import org.springframework.beans.factory.annotation.Configurable;
 8
 9 @Configurable("order")
10 public class Order implements Serializable {
11    private static final long serialVersionUID = 1L;
12    private Customer customer;
13    private List<Pizza> pizzas;
14    private Payment payment;
15
16    public Order() {
17       pizzas = new ArrayList<Pizza>();
18       customer = new Customer();
19    }
20
21    public Customer getCustomer() {
22       return customer;
23    }
24
25    public void setCustomer(Customer customer) {
26       this.customer = customer;
27    }
28
29    public List<Pizza> getPizzas() {
30       return pizzas;
31    }
32
33    public void setPizzas(List<Pizza> pizzas) {
34       this.pizzas = pizzas;
35    }
36
37    public void addPizza(Pizza pizza) {
38       pizzas.add(pizza);
39    }
40
41    public float getTotal() {
42       return 0.0f;//pricingEngine.calculateOrderTotal(this);
43    }
44
45    public Payment getPayment() {
46       return payment;
47    }
48
49    public void setPayment(Payment payment) {
50       this.payment = payment;
51    }
52
53 //   // injected
54 //   private PricingEngine pricingEngine;
55 //   public void setPricingEngine(PricingEngine pricingEngine) {
56 //      this.pricingEngine = pricingEngine;
57 //   }
58 }

4.执行过程

The order flow variable will be populated by the first three states and then saved in the fourth state. The identifyCustomer subflow state uses the <output> element to populate the order ’s customer property, setting it to the output received from calling the customer subflow. The buildOrder and takePayment states take a different approach, using <input> to pass the order flow variable as input so that those subflows can populate the order internally.

After the order has been given a customer, some pizzas, and payment details, it’s time to save it. The saveOrder state is an action state that handles that task. It uses <evaluate> to make a call to the saveOrder() method on the bean whose ID is pizza FlowActions , passing in the order to be saved. When it’s finished saving the order, it transitions to thankCustomer .
The thankCustomer state is a simple view state, backed by the JSP file at / WEB-INF /flows/pizza/thankCustomer.jsp, as shown next.

 1 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
 2 <html>
 3
 4   <head><title>Spring Pizza</title></head>
 5
 6   <body>
 7     <h2>Thank you for your order!</h2>
 8
 9 <form:form>
10     <input type="hidden" name="_flowExecutionKey"
11            value="${flowExecutionKey}"/>
12     <input type="submit" name="_eventId_finished" value="Finished" />
13 </form:form>
14
15 <form:form>
16   <input type="hidden" name="_flowExecutionKey"
17          value="${flowExecutionKey}"/>
18   <input type="hidden" name="_eventId"
19          value="finished" /><!-- Fire finished event   -->
20   <input type="submit" value="Finished" />
21 </form:form>
22
23
24     <a href='${flowExecutionUrl}&_eventId=finished'>Finish</a>
25     </body>
26 </html>

This link is the most interesting thing on the page, because it shows one way that a user can interact with the flow.
Spring Web Flow provides a flowExecutionUrl variable, which contains the URL for the flow, for use in the view. The Finish link attaches an _eventId parameter to the URL to fire a finished event back to the web flow. That event sends the flow to the end state.
At the end state, the flow ends. Because there are no further details on where to go after the flow ends, the flow will start over again at the identifyCustomer state, ready to take another pizza order.

转载于:https://www.cnblogs.com/shamgod/p/5248121.html

SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-003-Pizza例子的基本流程相关推荐

  1. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-008-SpEL介绍

    一. 1.SpEL expressions are framed with  #{ ... } 2.SpEl的作用 Sp EL has a lot of tricks up its sleeves, ...

  2. SPRING IN ACTION 第4版笔记-第二章-004-Bean是否单例

    spring的bean默认是单例,加载容器是会被化,spring会拦截其他再次请求bean的操作,返回spring已经创建好的bean. It appears that the CompactDisc ...

  3. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-003-@Conditional根据条件生成bean及处理profile...

    一.用@Conditional根据条件决定是否要注入bean 1. package com.habuma.restfun;public class MagicBean {} 2. package co ...

  4. SPRING IN ACTION 第4版笔记-第二章-002-@ComponentScan、@Autowired的用法

    一.@ComponentScan 1. @Configuration //说明此类是配置文件 @ComponentScan //开启扫描,会扫描当前类的包及其子包 public class CDPla ...

  5. SPRING IN ACTION 第4版笔记-第二章-001-用@Autowired\@ComponentScan、@Configuration、@Component实现自动装载bean...

    1. 1 package soundsystem; 2 import org.springframework.context.annotation.ComponentScan; 3 import or ...

  6. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-008-带参数的ADVICE

    一. 假设有情形如:cd里有很多轨,当播放音乐时,要统计每个音轨的播放次数,这些统计操作不应放在播放方法里,因为统计不是播放音乐的主要职责,这种情况适合应用AOP. 二. 1. package sou ...

  7. SPRING IN ACTION 第4版笔记-第四章Aspect-oriented Spring-001-什么是AOP

    一. Aspect就是把会在应用中的不同地方重复出现的非业务功能的模块化,比如日志.事务.安全.缓存 In software development, functions that span mult ...

  8. 《Spring in action,3th》阅读笔记

    第一章 Spring核心 第二章 装配Bean 第三章 最小化Spring XML配置

  9. 第二章 装配Bean(Spring in action,3th)

                                         第二章 装配Bean 创建应用对象之间协作关系的行为通常被称为装配(wiring),是依赖注入的本质. XML方式声明Bean ...

  10. Spring In Action 4

    在线学习连接:spring in action 4 文章目录 关键词解释 一.Spring的核心 1.1 简化Java开发 1.1.1 激发POJO的潜能 1.1.2 依赖注入 1.1.3 应用切面 ...

最新文章

  1. Windows下MongoDB的安装与设置MongoDB服务
  2. java 正则匹配括号是否成对_十分钟学会正则表达式
  3. android 图片弹跳效果,设置点的弹跳效果
  4. CSS-fishc学习笔记
  5. MySql Server 5.5安装教程
  6. 双稳态电路的两个稳定状态是什么_单稳态电路与双稳态电路
  7. 浪潮存储服务器VAAI
  8. 通过宏函数计算结构体成员偏移量
  9. 下载到的电子书格式是Mobi,这种格式能否在WINDOWS电脑上打开?
  10. Composer 源切换/composer 镜像网
  11. Atcoder F - Mirrored(思维+搜索)
  12. 分形蕨( fractal fern)
  13. 【FLASH自制游戏】轮之数袭
  14. 徐州市大数据管理中心市级政务云灾备服务
  15. 【博客418】cpu平坦模型和分段模型
  16. 自动驾驶 - 滤波算法
  17. 【AI】人工智能导论 小白零基础入门学习
  18. SK9815 (48bit )集成幻彩灯
  19. 《MLB美职棒大联盟》:年度救援王奖·棒球1号位
  20. opencv图像处理之轮廓外背景颜色改变

热门文章

  1. DWT(离散小波变换)与其简单应用
  2. 12行代码拿下所有lol皮肤!!Python超简单爬虫【内附详细教学 】
  3. 计算机学院 名言,计算机系网络毕业名言
  4. Acrel-2000T无线测温产品方案介绍(安科瑞-须静燕)
  5. chemdraw如何改中文_教你如何快速自定义ChemDraw默认设置
  6. 南京周边城市两日游方案
  7. 如何使用PDF Expert将文本添加到PDF?
  8. java ftp上传文件 linux_linux下用java实现ftp上传、下载文件
  9. 微商如何利用微信公众号来盈利
  10. 如何画出一张优秀的架构图(老鸟必备)