zoukankan      html  css  js  c++  java
  • Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)

    package cn.bdqn.mhouse.dao.impl;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import javax.print.attribute.standard.PagesPerMinute;
    
    import org.apache.ibatis.session.SqlSession;
    
    import cn.bdqn.mhouse.dao.IHouseDao;
    import cn.bdqn.mhouse.entity.House;
    import cn.bdqn.mhouse.entity.HouseCondition;
    import cn.bdqn.mhouse.entity.Street;
    import cn.bdqn.mhouse.entity.Types;
    import cn.bdqn.mhouse.util.MybatisUtil;
    import cn.bdqn.mhouse.util.Page;
    /**
     * 
    *    
    * 项目名称:mhouse   
    * 类名称:HouseDaoMybatisImpl   
    * 类描述:   房屋信息的操作类
    * 创建人:Mu Xiongxiong  
    * 创建时间:2017-3-15 下午4:04:07   
    * 修改人:Mu Xiongxiong   
    * 修改时间:2017-3-15 下午4:04:07   
    * 修改备注:   
    * @version    
    *
     */
    public class HouseDaoMybatisImpl implements IHouseDao {
    
    	House house=new House();
    	/**
    	 * (非 Javadoc)
    	* <p>Title: deleteByPrimaryKey</p>
    	* <p>Description(描述):根据id删除房屋信息 </p>
    	* @param id
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#deleteByPrimaryKey(java.lang.Integer)
    	 */
    	@Override
    	public int deleteByPrimaryKey(Integer id) {
    		SqlSession session=MybatisUtil.getSession();
    		int rel=0;
    		try {
    			rel = session.delete("houseDao.deleteByPrimaryKey",id);
    			session.commit();
    		} catch (Exception e) {
    			// TODO 异常执行块!
    			e.printStackTrace();
    			session.rollback();
    		}finally{
    			MybatisUtil.closeSession();
    		}
    		return rel;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: insert</p>
    	* <p>Description(描述): 添加房屋信息</p>
    	* @param record
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#insert(cn.bdqn.mhouse.entity.House)
    	 */
    	@Override
    	public int insert(House record) {
    		SqlSession session=MybatisUtil.getSession();
    		int rel=0;
    		try {
    			rel = session.insert("houseDao.insert",record);
    			session.commit();
    		} catch (Exception e) {
    			// TODO 异常执行块!
    			e.printStackTrace();
    		}finally{
    			MybatisUtil.closeSession();
    		}
    		return rel;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: selectByPrimaryKey</p>
    	* <p>Description(描述):根据id查询房屋信息 </p>
    	* @param id
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#selectByPrimaryKey(java.lang.Integer)
    	 */
    	@Override
    	public House selectByPrimaryKey(Integer id) {
    		SqlSession session=MybatisUtil.getSession();
    		House house=null;
    		try {
    			house=session.selectOne("houseDao.selectByPrimaryKey",id);
    			
    		} catch (Exception e) {
    			// TODO 异常执行块!
    			e.printStackTrace();
    		}finally{
    			MybatisUtil.closeSession();
    		}
    		return house;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: updateByPrimaryKey</p>
    	* <p>Description(描述): 根据id修改房屋信息</p>
    	* @param record
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#updateByPrimaryKey(cn.bdqn.mhouse.entity.House)
    	 */
    	@Override
    	public int updateByPrimaryKey(House record) {
    		SqlSession session=MybatisUtil.getSession();
    		int rel=0;
    		try {
    			rel=session.update("houseDao.updateByPrimaryKey",record);
    			session.commit();
    		} catch (Exception e) {
    			// TODO 异常执行块!
    			e.printStackTrace();
    			session.rollback();
    		}finally{
    			MybatisUtil.closeSession();
    		}
    		return rel;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: reCount</p>
    	* <p>Description(描述):动态查询总计录数</p>
    	* @param housec
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#reCount(cn.bdqn.mhouse.entity.HouseCondition)
    	 */
    	@Override
    	public int reCount(HouseCondition housec) {
    		SqlSession session=MybatisUtil.getSession();
    		Integer count=(Integer)session.selectOne("houseDao.reCount",housec);
    		return count;
    	}
    	
    	
    	
    	/**
    	 * (非 Javadoc)
    	* <p>Title: getHouseInfoByDymanic</p>
    	* <p>Description:‘动态分页查询房屋信息</p>
    	* @param housec
    	* @param pageIndex
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#getHouseInfoByDymanic(cn.bdqn.mhouse.entity.HouseCondition, int)
    	 */
    	@Override
    	public Page getHouseInfoByDymanic(HouseCondition housec,int pageIndex) {
    		Page page=new Page();
    		page.setPageIndex(pageIndex);      //当前页
    		int reCount=reCount(housec);       
    		page.setRecord(reCount);           //总记录数
    		List<House> houseList=new ArrayList<House>();
    		HashMap parMap=new HashMap();
    		parMap.put("priceBegin",housec.getPriceBegin());
    		parMap.put("priceEnd",housec.getPriceEnd());
    		if(housec.getStreet()!=null){
    		parMap.put("street",housec.getStreet());
    		}
    		if(housec.getTypes()!=null){
    			parMap.put("types",housec.getTypes());
    		}
    		parMap.put("floorageBegin", housec.getFloorageBegin());
    		parMap.put("floorageEnd",housec.getFloorageEnd());
    		parMap.put("stratRow",page.getSartRow());
    		parMap.put("endRow",page.getEndRow());
    		SqlSession session=MybatisUtil.getSession();
    		try {
    			houseList=session.selectList("houseDao.getHouseInfoByDymanic",parMap);
    			page.setHouseList(houseList);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}finally{
    			MybatisUtil.closeSession();
    		}
    		return page;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: getHouseInfo</p>
    	* <p>Description:查询所有房屋信息 </p>
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#getHouseInfo()
    	 */
    	@Override
    	public Page getHouseInfo() {
    		SqlSession session=MybatisUtil.getSession();
    		List<House> housel=session.selectList("houseDao.getHouseInfo");
    		Page page=new Page();
    		page.setHouseList(housel);
    		return page;
    	}
    
    	/**
    	 * (非 Javadoc)
    	* <p>Title: getHousePage</p>
    	* <p>Description(描述): 分页</p>
    	* @param pageIndex
    	* @param startRow
    	* @param endRow
    	* @return
    	* @see cn.bdqn.mhouse.dao.IHouseDao#getHousePage(int, int, int)
    	 */
    	@Override
    	public Page getHousePage(int pageIndex) {
    		SqlSession session=MybatisUtil.getSession();
    		HashMap parMap=new HashMap();
    		Page page=new Page();
    		HouseCondition housec=new HouseCondition();
    
    		page.setPageIndex(pageIndex);                   //当前页
    		parMap.put("startRow",page.getSartRow());      //开始记录
    		parMap.put("endRow",page.getEndRow());        //结束记录
    		page.setRecord(reCount(housec));             //总记录数
    		List<House> housel=session.selectList("houseDao.getHousePage",parMap);
    		page.setHouseList(housel);                 //详细信息
    		return page;
    	}
    
    }
    

  • 相关阅读:
    RadRails插件在MyEclipse的安装
    如何取消电脑的自动播放功能
    程序员怎么提高自己的技术书籍
    PHP网站,两个域名在一个空间,如何做301转向
    下载和安装Tcl/Tk:
    Hibernate 3.0配置Proxool 0.8.3数据库连接池
    CSS滤镜属性详解
    使用InstantRails搭建Ruby On Rails开发环境
    hibernate 二级缓存配置
    Ruby on rails开发从头来(windows)(二)创建项目和第一个Hello world
  • 原文地址:https://www.cnblogs.com/a1111/p/12816317.html
Copyright © 2011-2022 走看看