⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userserviceimp.java

📁 使用WEBWORK,SPRING,HIBERNATE编写的简单的添加
💻 JAVA
字号:
/**
 *文件功能:用户管理; InnoDB free: 0 kB 
 */
package com.tech.service.imp;

import java.util.List;
import com.common.dao.DaoSupport;
import com.common.dao.HibernateDaoHelper;
import com.common.exception.BusinessException;
import com.common.util.BeanUtils;
import com.common.util.DESUtils;
import com.tech.model.User;
import com.tech.service.UserService;

/**
 *用户管理; InnoDB free: 0 kB
 * @作者 徐建协
 * @日期 2009-02-25
 */
public class UserServiceImp implements UserService {
  private DaoSupport<User,Long> userDao;
  
  private HibernateDaoHelper hibernateDaoHelper;
  
  public void setUserDao(DaoSupport<User,Long> userDao) {
    this.userDao = userDao;
  }

  public User LoginUser(User entity) throws BusinessException {

		String sql="select count(id) as count from user where name=?";
		if(hibernateDaoHelper.countBySQL(sql, null, new Object[]{entity.getName()})<=0){
			throw new BusinessException("用户名输入错误");			
		}
		sql="select count(id) as count from user where name=? and password=?";
		if(hibernateDaoHelper.countBySQL(sql, null, new Object[]{entity.getName(),entity.getPassword()})<=0){
			throw new BusinessException("密码错误");			
		}
		sql="select id from user where name=? and password=?";
		String id=hibernateDaoHelper.getUniqueResult(sql, "id", new Object[]{entity.getName(),entity.getPassword()});	
		User user=userDao.getEntity(new Long(id));
       if(user==null){
    	   return null;
       }

		return user;
	}
  
  
  /* (non-Javadoc)
   * @see com.common.service.BaseService#getEntity(java.io.Serializable)
   */
  public User getEntity(Long id) throws BusinessException {
    try {
      return userDao.getEntity(id);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("UserServiceImp 不能获取主键为:" + id
          + "的数据" + e.toString());
    }
  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#loadEntity(java.io.Serializable)
   */
  public User loadEntity(Long id) throws BusinessException {
    try {
      return userDao.loadEntity(id);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("UserServiceImp 不能获取主键为:" + id
          + "的数据" + e.toString());
    }
  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#removeEntity(java.lang.Object)
   */
  public void removeEntity(User entity) throws BusinessException {
    try {
      userDao.removeEntity(entity);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("删除异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#removeEntity(T[])
   */
  public void removeEntity(User[] array) throws BusinessException {
    try {
      userDao.removeEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("删除异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#saveEntity(java.lang.Object)
   */
  public void saveEntity(User entity) throws BusinessException {
    try {
      userDao.saveEntity(entity);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("添加异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#saveEntity(T[])
   */
  public void saveEntity(User[] array) throws BusinessException {
    try {
      userDao.saveEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("添加异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#updateEntity(java.lang.Object)
   */
  public void updateEntity(User entity) throws BusinessException {
    try {
      
      User entityLoad = userDao.getEntity(entity.getId());
      // 拷贝不需要更新的字段内容
      //PropertyUtils.copyProperties(entityLoad,entity);
      BeanUtils.copyProperties(entityLoad,entity);
      userDao.updateEntity(entityLoad);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("更新异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#updateEntity(T[])
   */
  public void updateEntity(User[] array) throws BusinessException {
    try {
      userDao.updateEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("更新异常:"
          + e.getMessage());
    }

  }
  
  public boolean isExists(User t,List<String> names) throws BusinessException{
    try {
      return userDao.isExists(t,names);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("查找异常:"
          + e.getMessage());
    } 
  }

  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -