- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试创建一个与数据库连接的简单注册表单时,出现此错误。我用的是Ubuntu。这是我的代码:
Signup.java
package controllers;
import models.User;
import play.data.Form;
import play.mvc.*;
import views.html.signup.*;
import views.html.*;
public class Signup extends Controller{
public static Form<User> form = form(User.class);
public static Result blank(){
return ok(formsu.render(form));
}
public static Result submit(){
Form<User> fillForm = form.bindFromRequest(); // Play mark this line !!!
if(fillForm.hasErrors()) {
return badRequest(formsu.render(fillForm));
}
else{
User created = fillForm.get();
return ok(result.render(created));
}
}
}
用户.java
package models;
import java.util.List;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import play.data.validation.Constraints.Email;
import play.data.validation.Constraints.MinLength;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;
@Entity
public class User extends Model{
@Required@NotNull@MinLength(6)
public String username;
@Required@NotNull@MinLength(6)
public String password;
@Required@Email
public String email;
// public User(){}
//
// public User(String username,String password,String email){
// this.username=username;
// this.password=password;
// this.email=email;
// }
public static Finder<Long, User> find = new Finder(Long.class, User.class);
public static List<User> all(){
return find.all();
}
public static void create(User user){
user.save();
}
}
formsup.scala.html
@(user : Form[User])
@import helper._
@helper.form(action=routes.Signup.submit){
@inputText(
user("username"),
'_label -> "Username",
'_help -> "Put your username here"
)
@inputPassword(
user("password"),
'_label -> "Password",
'_help -> "Put your password here"
)
@inputPassword(
user("repeatpassword"),
'_label -> "Repeat password",
'_help -> "Put your password again"
)
@inputText(
user("email"),
'_label -> "Email",
'_help -> "Put your email here"
)
<input type="submit" value="Sign up" />
}
从终端:
--- (RELOAD) ---
[info] play - database [default] connected at jdbc:mysql://localhost/login
[info] play - Application started (Dev)
[error] application -
! @6f07fm4f0 - Internal server error, for request [POST /signup] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ValidationException: Call to TraversableResolver.isReachable() threw an exception]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.4]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.4]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.4]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1251) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:448) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139) ~[hibernate-validator.jar:4.2.0.Final]
Caused by: java.lang.RuntimeException: No @javax.persistence.Id field found in class [class models.User]
at play.db.ebean.Model._idAccessors(Model.java:39) ~[play_2.9.1.jar:2.0.4]
at play.db.ebean.Model._getId(Model.java:52) ~[play_2.9.1.jar:2.0.4]
at play.db.ebean.Model.hashCode(Model.java:183) ~[play_2.9.1.jar:2.0.4]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.buildHashCode(SingleThreadCachedTraversableResolver.java:153) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:114) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:96) ~[hibernate-validator.jar:4.2.0.Final]
“index”和“main”html都很好:(请帮我解决它。我尝试搜索它,但我无法修复这个错误。感谢您的帮助!!!
最佳答案
作为异常(exception)情况,您的模型需要使用 @Id
注释的 id 字段。Play 中还有验证库!将无法访问您的模型字段,因此您只需为 id
添加 getter 和 setter , username
, password
和email
字段。
关于java - 错误 ValidationException : Call to TraversableResolver. isReachable() 引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17588374/
我尝试手动验证实体图。使用 Hibernate SessionFactory 时我没有遇到任何问题。自从我切换到 Hibernate JPA 后,嵌套实体不再被验证。为什么? Hibernate ev
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
当我尝试创建一个与数据库连接的简单注册表单时,出现此错误。我用的是Ubuntu。这是我的代码: Signup.java package controllers; import models.User;
我正在学习 play 框架 Play Framework 它在此代码的第一行给出错误。 Form filledForm = taskForm.bindFromRequest(); if(filledF
我遇到了以下错误 javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() t
我是一名优秀的程序员,十分优秀!