日期:2014-05-16  浏览次数:20485 次

Spring3.0+Struts2.2+Hibernate3.6+ExtJS3.2.0+DWR框架 整合三
一、实现业务层基础
1、业务层基础类接口
package com.hanz.service.base;


public interface BaseServcie {

/**
* 以对象类型和对象编号为标示,获取相对应的对象
*
* @param pojoClass
*            对象类型
* @param id
*            对象编号
* @return 获取的简单对象
* @exception RuntimeException
*/
public Object get(Class pojoClass, int id) throws RuntimeException;

/**
* 创建新对象
*
* @param pojo
*            Object 新对象
* @throws RuntimeException
*/
public boolean save(Object pojo) throws RuntimeException;

/**
* 更新已有对象
*
* @param pojo
*            Object 需要更新的对象
* @throws RuntimeException
*/
public boolean update(Object pojo) throws RuntimeException;

/**
* 以对象类型和对象编号为标示,删除相对应的对象
*
* @param pojoClass
*            对象类型
* @param id
*            对象编号
* @exception RuntimeException
*/
public boolean delete(Class pojo, Integer id) throws RuntimeException;

/**
* 删除集合中的全部对象
*
* @param pojo
*            pojo
* @param ids
*            要删除的ID集合
* @throws RuntimeException
*/
public boolean deleteAll(Class pojo, String[] ids) throws RuntimeException;

/**
* 插入或者更新对象
*
* @param pojo
*            Object 目标pojo对象
* @throws RuntimeException
*/
public boolean insertOrUpdate(Object pojo) throws RuntimeException;



}
2、业务层基础接口实现类
package com.hanz.service.base.imp;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hanz.dao.base.BaseDao;
import com.hanz.service.base.BaseServcie;

@Component("baseService")
public class BaseServiceImp implements BaseServcie {

private BaseDao baseDao;

@Resource(name = "baseDao")
public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseDao;
}

/*
* (non-Javadoc)
*
* @see com.hanz.service.BaseService.IBaseService#delete(java.lang.Class,
* long)
*/
public boolean delete(Class pojo, Integer id) throws RuntimeException {
try {
baseDao.delete(baseDao.loadById(pojo, id));
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

/*
* (non-Javadoc)
*
* @see com.hanz.service.BaseService.IBaseService#get(java.lang.Class, long)
*/
public Object get(Class pojoClass, int id) throws RuntimeException {
return baseDao.loadById(pojoClass, id);
}

/*
* (non-Javadoc)
*
* @see
* com.hanz.service.BaseService.IBaseService#insertOrUpdate(java.lang.Object
* )
*/
public boolean insertOrUpdate(Object pojo) throws RuntimeException {
try {
baseDao.insertOrUpdate(pojo);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

/*
* (non-Javadoc)
*
* @see com.hanz.service.BaseService.IBaseService#save(java.lang.Object)
*/
public boolean save(Object pojo) throws RuntimeException {
try {
b