gpt4 book ai didi

java - 错误 ValidationException : Call to TraversableResolver. isReachable() 引发异常

转载 作者:行者123 更新时间:2023-12-01 14:20:44 26 4
gpt4 key购买 nike

当我尝试创建一个与数据库连接的简单注册表单时,出现此错误。我用的是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 , passwordemail字段。

关于java - 错误 ValidationException : Call to TraversableResolver. isReachable() 引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17588374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com