简单的例子,检查一下
实体(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.
如果我将用户:“长ID”更改为“字符串ID”(以及方法),问题将消失。
我以为一开始,spring在将Long转换为String时有问题吗?但是可能不是,因为我们有一个数字,Long可以毫无问题地保存下来。
有人知道这个问题吗?
尝试使用
<form:select path="user.id">
<c:forEach items="${userlist}" var="user">
<form:option value="${user.id}" label="${user.telephone" />
</c:forEach>
</form:select>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句