这是我需要检索在 POST 中发送的数据的代码:
@play.db.jpa.Transactional
public static Result registered(String fullname, String email, String password, String username) {
if(fullname.isEmpty()){
return badRequest("<p>fehlerhafte eingabe!</p>").as("text/html");
} else {
User user = new User();
user.fullname = fullname;
user.email = email;
user.password = password;
user.username = username;
user.save();
}
String success = "Successful registered!";
return ok(register.render(success));
}
这是我的用户类:
public class User extends Model {
private static final long serialVersionUID = 1L;
public String fullname;
@Email
public String email;
@Required(message="Username erforderlich!")
public String username;
@Transient @Required
public String password;
public User(){}
public User(String username, String password, String fullname, String email) {
this.username = username;
this.password = password;
this.email = email;
this.fullname = fullname;
}
这是我的html:
<form method="post" action="@routes.Application.registered()">
<p id="login_panel">@success</p>
fullname: <input type="text" name="fullname" id="fullname" value=""/>
email: <input type="text" name="email" id="email" value=""/>
username: <input type="text" name="username" id="username" value=""/>
password: <input type="password" name="password" id="password" value=""/>
<button type="submit">Register</button>
</form>
这是我的路线:
POST /registered controllers.Application.registered()
什么是 WSRequest?这可以成为我问题的线索吗?
我很感激任何帮助!谢谢,谢谢