zoukankan      html  css  js  c++  java
  • 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;
        }
    工作小总结,有错请指出,谢谢。
  • 相关阅读:
    P2319 [HNOI2006]超级英雄
    P4302 [SCOI2003]字符串折叠
    P1122 最大子树和
    HDU——2089 不要62
    P4555 最长双回文串
    P1463 [HAOI2007]反素数
    P2412 查单词
    P2787 语文1(chin1)- 理理思维
    P3078 [USACO13MAR]扑克牌型Poker Hands
    ubuntu中desktop与alternate版本的区别(转载)
  • 原文地址:https://www.cnblogs.com/zilanghuo/p/5210815.html
Copyright © 2011-2022 走看看