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

📄 ryglserviceimp.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.exception.BusinessException;
import com.common.util.BeanUtils;
import com.tech.model.Rygl;
import com.tech.service.RyglService;
import com.common.dao.HibernateDaoHelper;
/**
 *人员管理; InnoDB free: 0 kB
 * @作者 徐建协
 * @日期 2009-03-13
 */
public class RyglServiceImp implements RyglService {
  private DaoSupport<Rygl,Long> ryglDao;
  private HibernateDaoHelper hibernateDaoHelper;
  
  public void setHibernateDaoHelper(HibernateDaoHelper hibernateDaoHelper) {
		this.hibernateDaoHelper = hibernateDaoHelper;
	}
  public void setRyglDao(DaoSupport<Rygl,Long> ryglDao) {
    this.ryglDao = ryglDao;
  }
  
  
  public Rygl LoginRygl(Rygl entity) throws BusinessException {
	   
		String sql="select count(id) as count from rygl where name=?";
		if(hibernateDaoHelper.countBySQL(sql, null, new Object[]{entity.getName()})<=0){
			throw new BusinessException("用户名输入错误");			
		}
		sql="select count(id) as count from rygl where name=? and password=?";
		if(hibernateDaoHelper.countBySQL(sql, null, new Object[]{entity.getName(),entity.getPassword()})<=0){
			throw new BusinessException("密码错误");		
		}
		
		sql="select id from rygl where name=? and password=?";
		String id=hibernateDaoHelper.getUniqueResult(sql, "id", new Object[]{entity.getName(),entity.getPassword()});	
		Rygl rygl=ryglDao.getEntity(new Long(id));
		if(rygl==null){
			return null;
		}
		sql="select {c.*} from rygl c where 1=1 order by id desc";		
		rygl.setId(rygl.getId());
		rygl.setName(entity.getName());
		return rygl;
	}
  
  /* (non-Javadoc)
   * @see com.common.service.BaseService#getEntity(java.io.Serializable)
   */
  public Rygl getEntity(Long id) throws BusinessException {
    try {
      return ryglDao.getEntity(id);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("RyglServiceImp 不能获取主键为:" + id
          + "的数据" + e.toString());
    }
  }

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

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

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#removeEntity(T[])
   */
  public void removeEntity(Rygl[] array) throws BusinessException {
    try {
      ryglDao.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(Rygl entity) throws BusinessException {
    try {
      ryglDao.saveEntity(entity);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("添加异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#saveEntity(T[])
   */
  public void saveEntity(Rygl[] array) throws BusinessException {
    try {
      ryglDao.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(Rygl entity) throws BusinessException {
    try {
      
      Rygl entityLoad = ryglDao.getEntity(entity.getId());
      // 拷贝不需要更新的字段内容
      //PropertyUtils.copyProperties(entityLoad,entity);
      BeanUtils.copyProperties(entityLoad,entity);
      ryglDao.updateEntity(entityLoad);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("更新异常:"
          + e.getMessage());
    }

  }

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

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



}

⌨️ 快捷键说明

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