mybatis_crud

@Resource
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }
//全部数据集
public List<T> selectAll() throws DataAccessException {
        List<T> result = new ArrayList<T>();
        try {
            result = this.getSqlSession().selectList(
                    getMapperNamespace() + "." + "selectAll");
        } catch (DataAccessException e) {
            throw e;
        }
        return result;
    }

public Integer getTotalCount(Object params) throws DataAccessException {
        return getSqlSession().selectOne(
                getMapperNamespace() + "." + "getTotalCount", params);
    }
//插入一条数据
@Override
    public boolean insertSelective(T entity) throws DataAccessException {
        return insert("insertSelective", entity);
    }
//根据主键查询
@Override
    public T selectByPrimaryKey(Integer pk) throws DataAccessException {
        T result = null;
        try {
            result = (T) this.getSqlSession().selectOne(
                    getMapperNamespace() + "." + "selectByPrimaryKey", pk);
        } catch (DataAccessException e) {
            throw e;
        }
        return result;
    }
//根据参数查询
@Override
    public boolean updateByMap(String id, Map<String, Object> map)
            throws DataAccessException {
        boolean flag = this.getSqlSession().update(getMapperNamespace() + "." + id,
                map) > 0 ? true : false;
        return flag;
    }

 

posted @ 2016-02-23 17:56  自朗活  阅读(206)  评论(0编辑  收藏  举报