Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SpringWebFlow中将多个模型绑定到单个视图?_Java_Spring_Jsp_Spring Mvc_Spring Webflow - Fatal编程技术网

Java 如何在SpringWebFlow中将多个模型绑定到单个视图?

Java 如何在SpringWebFlow中将多个模型绑定到单个视图?,java,spring,jsp,spring-mvc,spring-webflow,Java,Spring,Jsp,Spring Mvc,Spring Webflow,情况:我正在开发一个SpringMVCwebapp,并使用SpringWebFlow和tiles框架。我在DBcustomer和CustomerAddress中有两个表,我有两个模型类,分别命名为customerModel和CustomerAddressModel 现在,在my flow.xml中,我有以下视图状态: <var name = "cust" class = "com.model.CustomerModel"/> <view-state id = "custom

情况:我正在开发一个SpringMVCwebapp,并使用SpringWebFlow和tiles框架。我在DB
customer
CustomerAddress
中有两个表,我有两个模型类,分别命名为
customerModel
CustomerAddressModel

现在,在my flow.xml中,我有以下
视图状态

<var name = "cust" class = "com.model.CustomerModel"/> 

<view-state id = "customerViewState" view = "customer" model = "cust">

        <transition on="next" to="customerData"/>

    </view-state>
问题:现在
customer.jsp
中指定的表单有一些输入字段,其中包含
customerAddressModel
的属性值。因此,我想将
customerModel
以及
customerAddressModel
绑定到相同的视图状态
customerViewState
。我该怎么做呢?我查了spring DOC,但什么都找不到,请帮忙


注意:我无法修改我的sql表

您可以创建复合模型DTO

public class CompositeModelDto {

    private CustomerModel suctomer;

    private CustomerAddressModel address;

    //setters ang getters ...

}
并将其用作视图状态模型

<var name = "cust" class = "com.model.CustomerModel"/>
<var name = "address" class = "com.model.CustomerAddressModel"/>
<var name = "customerDto" class = "com.model.CompositeModelDto"/>

<view-state id = "customerViewState" view = "customer" model = "customerDto">
    <on-entry>
        <set name="customerDto.customer" value="cust"/>
        <set name="customerDto.address" value="address"/>
    </on-entry>

    <transition on="next" to="customerData"/>

</view-state>


更新
对于视图,我建议使用Spring的表单标记库。定义标记库

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

并将jsp中的表单替换为

<form:form method="POST" action="${flowExecutionUrl}&_eventId=next" modelAttribute="customerDto">
   <table>
    <tr>
        <td><form:label path="customer.name">Name</form:label></td>
        <td><form:input path="customer.name" /></td>
    </tr>
    <tr>
        <td><form:label path="customer.email">Email</form:label></td>
        <td><form:input path="customer.email" /></td>
    </tr>
    <tr>
        <td><form:label path="address.addressLine1">Address Line 1</form:label></td>
        <td><form:input path="address.addressLine1" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Submit"/>
        </td>
    </tr>
   </table>
</form:form>

名称
电子邮件
地址行1

set语句在做什么,为什么需要它们?@varunsinghal
set
statement将
value
表达式结果设置为
name
中定义的属性<代码>表示
customerDto.setCustomer(cust)
。这两个集合都需要将customer和address设置到DTO中,以便在jsp中引用它们。毫无疑问,我有一个business服务,它将customerModel作为输入参数,然后将该输入参数插入customer表中。我如何在这里做到这一点?我可以这样做:cusomerBuisness.createCustomer(customerDto.cust)?请帮忙@varunsinghal是的,您可以。我有点困惑如何在JSP中引用
customerModel
customerModel
变量,然后将此变量作为输入传递给
customerModel
业务服务,如果您能对此有所了解,这将非常有用
<form:form method="POST" action="${flowExecutionUrl}&_eventId=next" modelAttribute="customerDto">
   <table>
    <tr>
        <td><form:label path="customer.name">Name</form:label></td>
        <td><form:input path="customer.name" /></td>
    </tr>
    <tr>
        <td><form:label path="customer.email">Email</form:label></td>
        <td><form:input path="customer.email" /></td>
    </tr>
    <tr>
        <td><form:label path="address.addressLine1">Address Line 1</form:label></td>
        <td><form:input path="address.addressLine1" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Submit"/>
        </td>
    </tr>
   </table>
</form:form>