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;
        }
    工作小总结,有错请指出,谢谢。
  • 相关阅读:
    1-命令格式
    android default_workspace.xml
    多维算法思考(二):关于八皇后问题解法的探讨
    C#对excel的操作
    c#读取xml操作
    一个用 C# 实现操作 XML 文件的公共类代码
    如何使用 LINQ 执行插入、修改和删除操作
    C#--编程
    LINQ常用操作
    用线性组合表示两个数的最大公约数
  • 原文地址:https://www.cnblogs.com/zilanghuo/p/5210815.html
Copyright © 2011-2022 走看看