8. 输入/输出映射

每个流都有明确定义的输入/输出契约。 流程开始时可以传递输入属性,结束时可以返回输出属性。 在这方面,调用流程在概念上类似于调用具有以下签名的方法:spring-doc.cadn.net.cn

FlowOutcome flowId(Map<String, Object> inputAttributes);

其中 a流程结果具有以下签名:spring-doc.cadn.net.cn

public interface FlowOutcome {
   public String getName();
   public Map<String, Object> getOutputAttributes();
}

8.1. 输入

输入元素声明一个流输入属性,具体如下:spring-doc.cadn.net.cn

<input name="hotelId" />

输入值会保存在流量作用域中属性名称下。 例如,前述示例中的输入被保存在hotelID.spring-doc.cadn.net.cn

8.1.1. 声明输入类型

类型属性声明输入属性的类型:spring-doc.cadn.net.cn

<input name="hotelId" type="long" />

如果输入值与声明类型不匹配,则尝试类型转换。spring-doc.cadn.net.cn

8.1.2. 分配输入值

属性指定一个用于赋予输入值的表达式,具体如下:spring-doc.cadn.net.cn

<input name="hotelId" value="flowScope.myParameterObject.hotelId" />

如果表达式的值类型可以确定,则该元数据用于类型强制,如果不确定类型属性被指定。spring-doc.cadn.net.cn

8.1.3. 按需标记输入

必填属性强制输入不是空的,具体如下:spring-doc.cadn.net.cn

<input name="hotelId" type="long" value="flowScope.hotelId" required="true" />

8.2. 该输出元素

输出element 声明一个流输出属性。 输出属性在代表特定流程结果的终端状态中声明。 以下列表定义了输出元素:spring-doc.cadn.net.cn

<end-state id="bookingConfirmed">
    <output name="bookingId" />
</end-state>

输出值通过属性名称从流域获得。 例如,前述示例中的输出会被赋予预订ID变量。spring-doc.cadn.net.cn

8.2.1. 指定 a 的来源输出

属性表示特定的输出值表达式,具体如下:spring-doc.cadn.net.cn

<output name="confirmationNumber" value="booking.confirmationNumber" />

8.3. 检查点:输入/输出映射

你应该查看带有输入/输出映射的样本预订流程:spring-doc.cadn.net.cn

<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当新预订确认时输出属性。spring-doc.cadn.net.cn