1

我对 Spring MVC 框架真的很陌生,我现在迫切需要帮助。

出于某种原因,我的重定向不起作用,它给了我 HTTP 状态 400,控制台上没有错误,这就是它很难调试的原因。

场景:我有 2 个表格。第一种形式正确保存然后重定向到第二种形式,但是当我重复我的代码以将其传递给第三种形式时,我收到一个 http 400 错误。我很确定我复制了我在第一个表格中使用的内容。

看法:

<form:form method="POST" commandName="kiosk"
                action="${pageContext.request.contextPath}/kiosk/kiosk-initial-info-save.html">
<div align="center">
    <br /> 
    <div id="addKioskContainer">
    <div class="datagrid1" align="center" style="width: 33%;">
        <table align="center">
            <thead>
                <tr>
                    <th colspan="4" style="text-align: left;">Initial Information</th>
                </tr>
            </thead>
        </table>
    </div>
    <div>
        <table>
            <tr>
                <td>
                    <h3 align="left">&nbsp;&nbsp;You are applying for <label style="color: blue;">Restructured Loan</label> in <label style="color: blue;">Eastwood.</label></h3>
                </td>
            </tr>
        </table>
    </div>
        <div id="initialInfoContainer">
            <table cellpadding="0" cellspacing="10">
                <tr>
                    <td style="font-size: 12px;" >
                        <b>Purpose of Loan: </b>
                    </td>
                    <td>
                        <form:input path="loanPurpose" size="40"></form:input>
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <div id="applicantInfoContainer">
                <div class="datagrid2" align="center" style="width: 95%;">
                    <table align="center">
                        <thead>
                            <tr>
                                <th colspan="4" style="text-align: left;">Applicant's Information</th>
                            </tr>
                        </thead>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Last Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appLastName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>First Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appFirstName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Middle Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appMiddleName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Birthdate: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appBirthDate" size="20"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>w/ Comaker: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:checkbox path="withCoMaker"></form:checkbox>
                            </td>
                        </tr>
                    </table>
                </div>
        </div>
        <br />
        <div id="comakerInfoContainer">
                <div class="datagrid2" align="center" style="width: 95%;">
                    <table align="center">
                        <thead>
                            <tr>
                                <th colspan="4" style="text-align: left;">Comaker's Information</th>
                            </tr>
                        </thead>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Last Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerLastName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>First Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerFirstName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Middle Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerMiddleName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Birthdate: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerBirthDate" size="20"></form:input>
                            </td>
                        </tr>
                    </table>
                </div>
        </div>
        <br />
        <div align="center">
            <table>
                <tr>
                    <td align="center"><input type="submit" value="Next" id="btnProceedKiosk"/></td>
                    <td></td>
                </tr>

            </table>
        </div>
    </div>
</div>

控制器:

 @RequestMapping( value = "/kiosk-initial-info", method = RequestMethod.GET )
public ModelAndView initialInfoKioskPage()
{
    ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );

    modelAndView.addObject( "kiosk", new Kiosk() );

    return modelAndView;
}

@RequestMapping( value = "/kiosk-initial-info-save", method = RequestMethod.POST )
public ModelAndView saveInitialInfo( @ModelAttribute
Kiosk kiosk )
{
    ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );

    modelAndView.addObject( "kiosk", new Kiosk() );

    return new ModelAndView( "redirect:/kiosk/kiosk-initial-info.html" );
}

模型:

    package com.etel.kiosk.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table( name = "kioskmain" )
public class Kiosk
{

    @Id
    @GeneratedValue
    private Integer id;

    private String loanType;

    private String branch;

    private String loanPurpose;

    private String appLastName;

    private String appFirstName;

    private String appMiddleName;

    private Date appBirthDate;

    private Boolean withCoMaker;

    private String comakerLastName;

    private String comakerFirstName;

    private String comakerMiddleName;

    private Date comakerBirthDate;

    public Integer getId()
    {
        return id;
    }

    public void setId( Integer id )
    {
        this.id = id;
    }

    public String getLoanType()
    {
        return loanType;
    }

    public void setLoanType( String loanType )
    {
        this.loanType = loanType;
    }

    public String getBranch()
    {
        return branch;
    }

    public void setBranch( String branch )
    {
        this.branch = branch;
    }

    public String getLoanPurpose()
    {
        return loanPurpose;
    }

    public void setLoanPurpose( String loanPurpose )
    {
        this.loanPurpose = loanPurpose;
    }

    public String getAppLastName()
    {
        return appLastName;
    }

    public void setAppLastName( String appLastName )
    {
        this.appLastName = appLastName;
    }

    public String getAppFirstName()
    {
        return appFirstName;
    }

    public void setAppFirstName( String appFirstName )
    {
        this.appFirstName = appFirstName;
    }

    public String getAppMiddleName()
    {
        return appMiddleName;
    }

    public void setAppMiddleName( String appMiddleName )
    {
        this.appMiddleName = appMiddleName;
    }

    public Date getAppBirthDate()
    {
        return appBirthDate;
    }

    public void setAppBirthDate( Date appBirthDate )
    {
        this.appBirthDate = appBirthDate;
    }

    public Boolean getWithCoMaker()
    {
        return withCoMaker;
    }

    public void setWithCoMaker( Boolean withCoMaker )
    {
        this.withCoMaker = withCoMaker;
    }

    public String getComakerLastName()
    {
        return comakerLastName;
    }

    public void setComakerLastName( String comakerLastName )
    {
        this.comakerLastName = comakerLastName;
    }

    public String getComakerFirstName()
    {
        return comakerFirstName;
    }

    public void setComakerFirstName( String comakerFirstName )
    {
        this.comakerFirstName = comakerFirstName;
    }

    public String getComakerMiddleName()
    {
        return comakerMiddleName;
    }

    public void setComakerMiddleName( String comakerMiddleName )
    {
        this.comakerMiddleName = comakerMiddleName;
    }

    public Date getComakerBirthDate()
    {
        return comakerBirthDate;
    }

    public void setComakerBirthDate( Date comakerBirthDate )
    {
        this.comakerBirthDate = comakerBirthDate;
    }

}

道实现

public void updateKiosk( Kiosk kiosk )
{
    Kiosk kioskToUpdate = getKiosk( kiosk.getId() );
    kioskToUpdate.setBranch( kiosk.getBranch() );
    kioskToUpdate.setLoanPurpose( kiosk.getLoanPurpose() );
    kioskToUpdate.setAppLastName( kiosk.getAppLastName() );
    kioskToUpdate.setAppFirstName( kiosk.getAppFirstName() );
    kioskToUpdate.setAppMiddleName( kiosk.getAppMiddleName() );
    kioskToUpdate.setAppBirthDate( kiosk.getAppBirthDate() );
    kioskToUpdate.setWithCoMaker( kiosk.getWithCoMaker() );
    kioskToUpdate.setComakerLastName( kiosk.getComakerLastName() );
    kioskToUpdate.setComakerFirstName( kiosk.getComakerFirstName() );
    kioskToUpdate.setComakerMiddleName( kiosk.getComakerMiddleName() );
    kioskToUpdate.setComakerBirthDate( kiosk.getComakerBirthDate() );
    getCurrentSession().update( kioskToUpdate );
}

你的回答会有很大帮助。谢谢。

4

0 回答 0