8. 输入/输出映射
每个流程都有明确的输入/输出约定。 流程在启动时可以传入输入属性,并在结束时返回输出属性。 从这个意义上来说,调用一个流程在概念上类似于调用具有以下签名的方法:
FlowOutcome flowId(Map<String, Object> inputAttributes);
Where a FlowOutcome 具有以下签名:
public interface FlowOutcome {
public String getName();
public Map<String, Object> getOutputAttributes();
}
8.1. 输入
input 元素声明了一个流输入属性,如下所示:
<input name="hotelId" />
输入的值会以属性名称保存在流范围中。 例如,前面示例中的输入会以hotelId的名称保存。
8.2. output元素
output 元素声明了一个流输出属性。 输出属性是在表示特定流结果的结束状态内声明的。 以下清单定义了一个 output 元素:
<end-state id="bookingConfirmed">
<output name="bookingId" />
</end-state>
输出值是从流范围中根据属性的名称获取的。 例如,前面示例中的输出将被赋值为 bookingId 变量的值。
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 输入属性,并在新预订确认时返回一个 bookingId 输出属性。