您的位置:首页 > 编程语言

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

2018-04-02 13:48 567 查看

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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ssh
相关文章推荐