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;
        }
    工作小总结,有错请指出,谢谢。
  • 相关阅读:
    企业库连接形式简单例子记录 EnterpriseLibrary.Data
    .net 抽象类(abstract)和接口(interface)区别
    windows service 开发、安装及调试
    asp.net(mvc) 框架
    获取IP地址
    select2 模糊查询远程数据
    设计模式篇——初探命令模式
    初探MVC路由
    初探表达式目录树
    C#实现插入排序法
  • 原文地址:https://www.cnblogs.com/zilanghuo/p/5210815.html
Copyright © 2011-2022 走看看