How to query (EBean & Play Framework) to see if a certain value is in a certain column in a certain table?

不打扰是莪最后的温柔 提交于 2019-12-11 21:01:01

问题


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.

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.

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.

The user model that is connected to Ebean can be found here: https://github.com/Axsel/PonyCentral/blob/master/app/models/User.java

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.

Thank you much.


回答1:


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");


来源:https://stackoverflow.com/questions/23774217/how-to-query-ebean-play-framework-to-see-if-a-certain-value-is-in-a-certain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!