客户端发送的请求在语法上是不正确的。 <form:option

时间:2015-05-09 04:03:55

标签: spring model-view-controller

=“”

我收到了#34;客户端发送的请求在语法上是不正确的。&#34;同时持久化访客对象。如果我删除了

VisitorDetails.java

   @Entity
    @Table(name = "visitor_details")
         public class VisitorDetails {
           @Id
           @GeneratedValue(strategy = GenerationType.AUTO)
           private int id;
           @Column(name = "first_name")
           private String firstName;
           @Column(name = "last_name")
           private String lastName;
           private String mobileNumber;
           @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
           @JoinColumn(name = "society_id")
           private SocietyDetails societyDetails;
           public SocietyDetails getSocietyDetails() {
            return societyDetails;
           }

SocietyDetails.java

@Entity
@Table(name = "society_details")
public class SocietyDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    @Column(name = "society_name")
    private String societyName;
    @Column(name = "society_address")
    private String societyAddress;

visitor.jsp

 <form:form action="${pageContext.request.contextPath}/visitor/add"
                commandName="visitor">
                <table>
                    <tr>
                        <td>First Name:</td>
                        <td><form:input path="firstName" /></td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td><form:input path="lastName" /></td>
                    </tr>
                    <tr>
                        <td>Mobile Number:</td>
                        <td><form:input path="mobileNumber" /></td>
                    </tr>
                    <tr>
                        <td>Society:</td>
                        <td><form:select path="societyDetails">
                                <form:option value="" label="Select Society" />
                                <form:options items="${societyDetailsLst}"
                                    itemLabel="societyName" itemValue="id" />
                            </form:select></td> 
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" value="Save Changes" />
                        </td>
                    </tr>
                </table>
            </form:form>

控制器类 - VisitorController.java

    @RequestMapping(value = "/visitor/add", method = RequestMethod.POST)
    public String addVisitor(@ModelAttribute("visitor") VisitorDetails visitorDet) {
      visitorService.create(visitorDet);
     return "visitor";
 }

0 个答案:

没有答案