/***********************************************
 * Filename       : HibernateUserDao.java
 * Copyright      : Copyright (c) 2014
 * Company        : Innovaee
 * Created        : 11/27/2014
 ************************************************/
package com.innovaee.eorder.dao.hibernate;

import com.innovaee.eorder.dao.UserDao;
import com.innovaee.eorder.entity.User;

import java.util.List;

/**
 * @Title: HibernateUserDao
 * @Description: 用户数据访问对象实现类
 * 
 * @version V1.0
 */
public class HibernateUserDao extends HibernateBaseDao<User> implements UserDao {

    /**
     * 根据手机号码得到用户
     * 
     * @param cellphone
     *            手机号码
     * @return 用户
     */
    public User getUserByCellphone(String cellphone) {
        String hql = "from User as user where user.cellphone = ?";
        Object[] paras = { cellphone };
        List<User> users = getPage(0, 1, hql, paras);
        if (0 != users.size()) {
            return users.get(0);
        }

        return null;
    }

}
@@ -41,16 +41,17 @@
 ********
+%0D
 %0A * File
@@ -84,16 +84,17 @@
 Dao.java
+%0D
 %0A * Copy
@@ -124,16 +124,17 @@
 (c) 2014
+%0D
 %0A * Comp
@@ -154,16 +154,17 @@
 Innovaee
+%0D
 %0A * Crea
@@ -186,16 +186,17 @@
 /27/2014
+%0D
 %0A ******
@@ -238,16 +238,17 @@
 *******/
+%0D
 %0Apackage
@@ -282,17 +282,19 @@
 bernate;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -325,16 +325,17 @@
 UserDao;
+%0D
 %0Aimport 
@@ -370,17 +370,19 @@
 ser;
-%0A
+%0D%0A%0D
 %0Aimport 
 java
@@ -381,28 +381,178 @@
 ort 
-java.util.List;%0A
+org.hibernate.Criteria;%0D%0Aimport org.hibernate.Session;%0D%0Aimport org.hibernate.criterion.Restrictions;%0D%0Aimport org.springframework.orm.hibernate3.HibernateCallback;%0D%0A%0D
 %0A/**
+%0D
 %0A * 
@@ -575,16 +575,17 @@
 eUserDao
+%0D
 %0A * @Des
@@ -605,20 +605,22 @@
 %E6%8D%AE%E8%AE%BF%E9%97%AE%E5%AF%B9%E8%B1%A1%E5%AE%9E%E7%8E%B0%E7%B1%BB
+%0D
 %0A * 
+%0D
 %0A * @ver
@@ -632,12 +632,14 @@
 V1.0
+%0D
 %0A */
+%0D
 %0Apub
@@ -720,17 +720,19 @@
 ao %7B
-%0A
+%0D%0A%0D
 %0A    /**
 %0A   
@@ -727,16 +727,17 @@
 %0A    /**
+%0D
 %0A     * 
@@ -746,24 +746,25 @@
 %E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81%E5%BE%97%E5%88%B0%E7%94%A8%E6%88%B7
+%0D
 %0A     * 
 %0A     * 
@@ -755,16 +755,17 @@
 %0A     * 
+%0D
 %0A     * 
@@ -780,16 +780,17 @@
 ellphone
+%0D
 %0A     * 
@@ -804,16 +804,17 @@
     %E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81
+%0D
 %0A     * 
@@ -827,16 +827,17 @@
 n %E7%94%A8%E6%88%B7
+%0D
 %0A     */
 %0A   
@@ -832,16 +832,17 @@
 %0A     */
+%0D
 %0A    pub
@@ -869,16 +869,22 @@
 llphone(
+final 
 String c
@@ -894,17 +894,20 @@
 phone) %7B
-%0A
+%0D%0A//
         
@@ -964,17 +964,20 @@
 ne = ?%22;
-%0A
+%0D%0A//
         
@@ -1007,17 +1007,20 @@
 phone %7D;
-%0A
+%0D%0A//
         
@@ -1064,17 +1064,20 @@
  paras);
-%0A
+%0D%0A//
         
@@ -1100,17 +1100,20 @@
 ize()) %7B
-%0A
+%0D%0A//
         
@@ -1136,17 +1136,20 @@
 .get(0);
-%0A
+%0D%0A//
         
@@ -1149,18 +1149,24 @@
        %7D
-%0A%0A
+%0D%0A//%0D%0A//
         
@@ -1181,13 +1181,462 @@
 ull;
+%0D
 %0A    
-%7D%0A
+    %0D%0A        return getHibernateTemplate().execute(new HibernateCallback%3CUser%3E()%7B%0D%0A            %0D%0A            public User doInHibernate(Session session) %7B%0D%0A                Criteria criteria = session.createCriteria(User.class);%0D%0A                %0D%0A                criteria.add(Restrictions.eq(%22cellphone%22, cellphone));%0D%0A                %0D%0A                return (User)(criteria.list().iterator().next());%0D%0A            %7D%0D%0A        %7D);%0D%0A        %0D%0A    %7D%0D%0A%0D
 %0A%7D

Use Hibernate Criteria to query User by cellphone