我的计划有什么问题?我收到错误
HTTP Status 500 - Request processing failed; nested exception is javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Long.
并且不知道如何解决它...在堆栈跟踪中,我编写的唯一类是
myapp.spring.controllers.PostFormController.processForm(PostFormController.java:66)
这一行是
validator.validate(p, result);
Post.java
// imports
@Entity
@Table(name="posts")
public class Post implements Serializable
{
/* **********************************
* ------------ fields ------------ *
************************************/
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@Past
@Column(name="date")
private Date date;
@NotBlank
@Size(min=3, max=20)
@Column(name="author")
private String author;
@NotBlank
@Column(name="content")
private String content;
@NotBlank
@Column(name="topic")
private String topic;
@NotBlank
@Column(name="thread_id")
private long thread_id;
@ManyToOne
@JoinColumn(name="name")
@Valid
private PostType type;
/* ***************************************
* ---------- getters setters ---------- *
*****************************************/
// cut //
}
blah blah blah无法添加,因为帖子中的代码太多了:S
答案 0 :(得分:7)
问题可能是这一行:
@NotBlank
@Column(name="thread_id")
private long thread_id;
NotBlank
对long类型的字段没有意义。长期不能空白或不空白。只有一个字符串可以。因此错误消息:
javax.validation.UnexpectedTypeException:HV000030:找不到类型的验证程序:java.lang.Long