这是我的代码,我需要检索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?这可能是我的问题的线索吗?
我感谢任何帮助!谢谢,谢谢
答案 0 :(得分:2)
您“注册”的操作不需要任何参数。
这些参数在请求中提供,您可以使用built in form binding获取这些参数:
public static Result registered(String fullname, String email, String password, String username) {
User user = form(User.class).bindFromRequest().get();
....
}
答案 1 :(得分:0)
您需要检查控制器类代码。您应该将所有字段名称作为被调用控制器方法中的参数。然后,您可以在申请中使用这些文件。