8. 输入/输出映射
每个流都有明确定义的输入/输出契约。 流程开始时可以传递输入属性,结束时可以返回输出属性。 在这方面,调用流程在概念上类似于调用具有以下签名的方法:
FlowOutcome flowId(Map<String, Object> inputAttributes);
其中 a流程结果具有以下签名:
public interface FlowOutcome {
public String getName();
public Map<String, Object> getOutputAttributes();
}
8.1. 输入
这输入元素声明一个流输入属性,具体如下:
<input name="hotelId" />
输入值会保存在流量作用域中属性名称下。
例如,前述示例中的输入被保存在hotelID.
8.2. 该输出元素
这输出element 声明一个流输出属性。
输出属性在代表特定流程结果的终端状态中声明。
以下列表定义了输出元素:
<end-state id="bookingConfirmed">
<output name="bookingId" />
</end-state>
输出值通过属性名称从流域获得。
例如,前述示例中的输出会被赋予预订ID变量。
8.3. 检查点:输入/输出映射
你应该查看带有输入/输出映射的样本预订流程:
<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
https://www.springframework.org/schema/webflow/spring-webflow.xsd">
<input name="hotelId" />
<on-start>
<evaluate expression="bookingService.createBooking(hotelId, currentUser.name)"
result="flowScope.booking" />
</on-start>
<view-state id="enterBookingDetails">
<transition on="submit" to="reviewBooking" />
</view-state>
<view-state id="reviewBooking">
<transition on="confirm" to="bookingConfirmed" />
<transition on="revise" to="enterBookingDetails" />
<transition on="cancel" to="bookingCancelled" />
</view-state>
<end-state id="bookingConfirmed" >
<output name="bookingId" value="booking.id"/>
</end-state>
<end-state id="bookingCancelled" />
</flow>
流现在接受hotelID输入属性,返回预订ID当新预订确认时输出属性。