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

📄 newserviceimp.java

📁 使用WEBWORK,SPRING,HIBERNATE编写的简单的添加
💻 JAVA
字号:
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.News;
import com.tech.service.NewService;

public class NewServiceImp implements NewService {

	private DaoSupport<News,Long> newDao;
	
	public void setNewDao(DaoSupport<News, Long> newDao) {
		this.newDao = newDao;
	}
	@Override
	public News getEntity(Long id) throws BusinessException {
		try {
			return newDao.getEntity(id);
		} catch (Exception e) {
			e.printStackTrace();
		    throw new BusinessException("NewServiceImp 不能获取主键为:" + id
		          + "的数据" + e.toString());
		}
	}

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

	@Override
	public News loadEntity(Long id) throws BusinessException {
		try {
		      return newDao.loadEntity(id);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("NewServiceImp 不能获取主键为:" + id
		          + "的数据" + e.toString());
		    }
	}

	@Override
	public void removeEntity(News entity) throws BusinessException {
		try {
		      newDao.removeEntity(entity);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("删除异常:"
		          + e.getMessage());
		    }
	}

	@Override
	public void removeEntity(News[] array) throws BusinessException {
		try {
		      newDao.removeEntity(array);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("删除异常:"
		          + e.getMessage());
		    }
	}

	@Override
	public void saveEntity(News entity) throws BusinessException {
		try {
		      newDao.saveEntity(entity);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("添加异常:"
		          + e.getMessage());
		    }
	}

	@Override
	public void saveEntity(News[] array) throws BusinessException {
		try {
		      newDao.saveEntity(array);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("添加异常:"
		          + e.getMessage());
		    }
	}

	@Override
	public void updateEntity(News entity) throws BusinessException {
		try {
		      
		      News entityLoad = newDao.getEntity(entity.getId());
		      // 拷贝不需要更新的字段内容
		      BeanUtils.copyProperties(entityLoad,entity);
		      newDao.updateEntity(entityLoad);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("更新异常:"
		          + e.getMessage());
		    }
	}

	@Override
	public void updateEntity(News[] array) throws BusinessException {
		try {
		      newDao.updateEntity(array);
		    } catch (Exception e) {
		      e.printStackTrace();
		      throw new BusinessException("更新异常:"
		          + e.getMessage());
		    }
	}

}

⌨️ 快捷键说明

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