SSH-BOS项目:底层代码抽取(BaseDao、BaseAction)

BaseDao抽取:

package com.xushuai.bos.dao;

import java.io.Serializable;
import java.util.List;

import com.xushuai.bos.utils.PageBean;

/**
 * 持久层通用接口
 * @author xushuai
 *
 * @param <T>
 */
public interface BaseDao<T> {
	/**
	 * 添加一个entity
	 * @param entity
	 */
	public void save(T entity);
	
	/**
	 * 删除一个entity
	 * @param entity
	 */
    public void delete(T entity);
    
    /**
     * 修改一个entity
     * @param entity
     */
    public void update(T entity);
    
    /**
     * 按ID查询
     * @param id
     * @return
     */
    public T findById(Serializable id);
    
    /**
     * 查询所有
     * @param entity
     * @return
     */
    public List<T> findAll(T entity);
    
    /**
     * 分页查询
     * @param pageBean
     */
    public void findByPage(PageBean pageBean);
    
    /**
     * 更新
     * @param queryName
     * @param objects
     */
    public void executeUpdate(String queryName,Object...objects);
    
    /**
     * 保存或更新
     * @param entity
     */
    public void saveOrUpdate(T entity);
                              

}

BaseAction抽取:

package com.xushuai.bos.web.action;

import java.lang.reflect.ParameterizedType;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
	public final static String HOME = "home";
	public final static String LIST = "list";
	
	protected T model;
	//获取运行时期实际类型,并对其进行实例化
	public BaseAction() {
		ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
		Class entityClass = (Class) type.getActualTypeArguments()[0];
		try {
			model = (T) entityClass.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}


	@Override
	public T getModel() {
		return model;
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值