我在使用java.util.Set绑定JSP表单时遇到问题。 我正在使用JPA和Hibernate,我无法将java.util.Set更改为java.util.List,因为这会影响我的数据库模型。
我的例外是:
[javax.servlet.ServletException:javax.servlet.jsp.JspException:org.springframework.beans.InvalidPropertyException:无效的属性'phones [0]'
我理解这个例外。但我不知道如何以JSP形式绑定java.util.Set。
有人可以帮助我吗?
@Entity
public class Phone implements Serializable {
private static final long serialVersionUID = 7507976788394149092L;
@Id
private String ddd;
@Id
private String number;
public String getDdd() {
return ddd;
}
public void setDdd(String ddd) {
this.ddd = ddd;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public void setPrincipal(boolean principal) {
this.principal = principal;
}
}
和
@Entity
public class Client {
@Id
@Column(columnDefinition = "CHAR(11)")
private String cpf;
@ManyToMany
private Set<Phone> phones = new HashSet<Phone>();
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public Set<Phone> getPhones() {
return phones;
}
public void setPhones(Set<Phone> phone) {
this.phones = phone;
}
}
和
...
<label for="dddPhone">DDD - Fixo</label>
<springForm:input path="phones.ddd" type="number" class="form-control" id="dddPhone" placeholder="DDD" />
...