首页 > 其他 > 详细

mybatis_crud

时间:2016-02-23 18:44:06      阅读:111      评论:0      收藏:0      [点我收藏+]
@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;
    }

 

mybatis_crud

原文:http://www.cnblogs.com/zilanghuo/p/5210815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!