如何查询(EBean和Play框架)以查看某个值是否在某个表的某个列中? [英] How to query (EBean & Play Framework) to see if a certain value is in a certain column in a certain table?
问题描述
因此,我建立了一个注册表,将信息保存到Play Framework中的数据库中.别为不存在的密码安全而烦恼,我还没有做到这一点.
So, I have set up a registration form that saves info to a database in Play Framework. Don't get caught up on the nonexistant password security, I haven't gotten to that.
我需要一种检查用户数据库中是否已存在电子邮件的方法.我只是不确定如何使用Ebean.
I need a way to check to see if an email is already in the user database. I'm simply not sure how to do that with Ebean.
表单模型存储在此处: https://github .com/Axsel/PonyCentral/blob/master/app/models/RegisterForm.java |在类底部的验证方法中,我需要能够检查用户表中是否有匹配的电子邮件. RegisterForm的email变量是表单的直接输入.
The form model is stored here: https://github.com/Axsel/PonyCentral/blob/master/app/models/RegisterForm.java | In the validation method seen at the bottom of the class I need to be able to check the user table for any matching emails. The email variable from RegisterForm is direct input from the form.
可以在以下位置找到连接到Ebean的用户模型: https://github.com/Axsel/PonyCentral/blob/master/app/models/User.java
The user model that is connected to Ebean can be found here: https://github.com/Axsel/PonyCentral/blob/master/app/models/User.java
最后,如果需要查看它,可以在以下位置找到表单请求处理程序:/app/controllers/User.java(StackOverflow不允许我链接两件事)
Lastly, if you need to see it, the form request handler can be found here: Under /app/controllers/User.java (StackOverflow won't let me link for than two things)
如果您能提供任何帮助,我将非常感谢.
If you could provide any help I would be very grateful.
非常感谢.
推荐答案
只需...查询数据库,即计算给定电子邮件的记录(从我的头顶写起):
Just... query the database i.e. count the records for given email (written from top of my head):
int count = User.find.where().like("email", "john@doe.com").findRowCount();
if (count>0) return badRequest("This email address already in use");
这篇关于如何查询(EBean和Play框架)以查看某个值是否在某个表的某个列中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!