博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-003-Pizza例子的基本流程
阅读量:4610 次
发布时间:2019-06-09

本文共 4797 字,大约阅读时间需要 15 分钟。

一、

1.

2.pizza-flow.xml

1 
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

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

1 
2
6 7
8 9
10
11
12
13
14 15
16
17
18
19
20 21
22
23
24
25
26 27
28
29
30
31 32
33
34
35 36
37
38 39
40
41
42

 

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

1 
2
7 ...8

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
pizzas;14 private Payment payment;15 16 public Order() {17 pizzas = new ArrayList
();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
getPizzas() {30 return pizzas;31 }32 33 public void setPizzas(List
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 // // injected54 // 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  3  4   Spring Pizza 5  6    7     

Thank you for your order!

8 9
10
12
13
14 15
16
18
20
21
22 23 24 Finish25 26

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

你可能感兴趣的文章
数据库的创建和删除
查看>>
最简单的三层实例【插入据
查看>>
设计模式学习笔记——Prototype原型模式
查看>>
pom.xml里有红叉报错的解决办法
查看>>
Perl last和next的用法区别
查看>>
Selenium 管理 Cookies
查看>>
exceptionfunction[LeetCode]Permutations
查看>>
Linux(2)_常用命令2
查看>>
自定义分页
查看>>
[转]DELPHI——调试(1)
查看>>
JS秒数转成分秒时间格式
查看>>
xp_cmdshell 命令的开启与关闭,和状态查询
查看>>
Linux sudoers
查看>>
MySQL详解(18)-----------分页方法总结
查看>>
bzoj 4595 激光发生器
查看>>
multi cookie & read bug
查看>>
js时间转换
查看>>
(转载) Android Studio你不知道的调试技巧
查看>>
队列实现霍夫曼树
查看>>
JAVA 笔记(一)
查看>>