0
簡單的例子,檢查Spring MVC表單 - 長和字符串值。通過客戶端發送的請求是語法不正確
實體(USER,MOBILEPHONE)
@Entity
@Table(name = "USER")
public class User {
private Long id
private String name;
private Set<Mobilephone> mobilephones= new HashSet<mobilephones>(0);
public User(Long id)
this.id = id
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
//getter and setter for name
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set<Mobilephone> getMobilephones() {
return this.mobilephones;
}
public void setMobilephones(Set<Mobilephone> mobilephones) {
this.mobilephones= mobilephones;
}
@Entity
@Table(name = "MOBILEPHONE")
public class Mobilephone {
private Long id
private Long number;
private User user
public MobilePhone(Long id)
this.id = id
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
//getter and setter for number
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USERID", nullable = false)
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user= user;
}
頁面
<form:form modelAttribute="mobilephoneAttribute" action="url" method="post">
<form:input path="mobilephone"/>
<form:select path="user">
<c:forEach items="${userlist}" var="user">
<form:option value="${user.id}" label="${user.telephone" />
</c:forEach>
</form:select>
<input type="submit"/>
</form:form>
請告訴我發生的事情。
後提交我得到這個錯誤:
The request sent by the client was syntactically incorrect.
如果我改變我的用戶:「龍號」到「串號」(也是方法)的問題消失。
我認爲在一開始,春天有一個問題,轉換爲長的字符串? 但是可能不會,因爲我們有一個數字,Long保存沒有問題。
有人知道這個問題嗎?
嘗試使用<形式:選擇路徑= 「user.id」> – 2014-08-27 15:38:18
你可以看到服務器日誌的任何錯誤? – coder 2014-08-27 15:39:11
@ ankur-singhal沒有這種情況沒有發生!有用!感謝隊友 – user2363971 2014-08-27 15:59:37