
Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)
发布日期:2021-05-14 13:06:19
浏览次数:16
分类:精选文章
本文共 4349 字,大约阅读时间需要 14 分钟。
package cn.bdqn.mhouse.dao.impl;
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
- 修改备注: */
public class HouseDaoMybatisImpl implements IHouseDao {
private static final String BASE_MAPPINGS = "houseDao.";private House house = new House();@Overridepublic int deleteByPrimaryKey(Integer id) { SqlSession session = MybatisUtil.getSession(); try { return session.delete(BASE_MAPPINGS + "deleteByPrimaryKey", id); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { MybatisUtil.closeSession(); } return 0;}@Overridepublic int insert(House record) { SqlSession session = MybatisUtil.getSession(); try { return session.insert(BASE_MAPPINGS + "insert", record); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { MybatisUtil.closeSession(); } return 0;}@Overridepublic House selectByPrimaryKey(Integer id) { SqlSession session = MybatisUtil.getSession(); try { return session.selectOne(BASE_MAPPINGS + "selectByPrimaryKey", id); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtil.closeSession(); } return null;}@Overridepublic int updateByPrimaryKey(House record) { SqlSession session = MybatisUtil.getSession(); try { return session.update(BASE_MAPPINGS + "updateByPrimaryKey", record); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { MybatisUtil.closeSession(); } return 0;}@Overridepublic int reCount(HouseCondition housec) { SqlSession session = MybatisUtil.getSession(); try { Integer count = session.selectOne(BASE_MAPPINGS + "reCount", housec); return count != null ? count.intValue() : 0; } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtil.closeSession(); } return 0;}@Overridepublic Page getHouseInfoByDymanic(HouseCondition housec, int pageIndex) { Page page = new Page(); page.setPageIndex(pageIndex); int reCount = reCount(housec); page.setRecord(reCount); ListhouseList = new ArrayList<>(); HashMap parMap = new HashMap(); if (housec.getPriceBegin() != null) { parMap.put("priceBegin", housec.getPriceBegin()); } if (housec.getPriceEnd() != null) { 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("startRow", page.getStartRow()); parMap.put("endRow", page.getEndRow()); SqlSession session = MybatisUtil.getSession(); try { houseList = session.selectList(BASE_MAPPINGS + "getHouseInfoByDymanic", parMap); page.setHouseList(houseList); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtil.closeSession(); } return page;}@Overridepublic Page getHouseInfo() { SqlSession session = MybatisUtil.getSession(); List housel = session.selectList(BASE_MAPPINGS + "getHouseInfo"); Page page = new Page(); page.setHouseList(housel); return page;}@Overridepublic Page getHousePage(int pageIndex) { SqlSession session = MybatisUtil.getSession(); Page page = new Page(); HashMap parMap = new HashMap(); HouseCondition housec = new HouseCondition(); page.setPageIndex(pageIndex); parMap.put("startRow", page.getStartRow()); parMap.put("endRow", page.getEndRow()); int reCount = reCount(housec); page.setRecord(reCount); List housel = session.selectList(BASE_MAPPINGS + "getHousePage", parMap); page.setHouseList(housel); return page;}
}
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年04月16日 00时03分19秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Frame--Api框架
2019-03-11
Frame--WEB框架
2019-03-11
idea 在Debug 模式中运行语句中函数的方法
2019-03-11
springboot2.1.1开启druid数据库连接池并开启监控
2019-03-11
《朝花夕拾》金句摘抄(五)
2019-03-11
《朝花夕拾》金句摘抄(六)
2019-03-11
《金色梦乡》金句摘抄(六)
2019-03-11
Boostrap技能点整理之【网格系统】
2019-03-11
新闻发布项目——业务逻辑层(UserService)
2019-03-11
hibernate正向生成数据库表以及配置——hibernate.cfg.xml
2019-03-11
javaWeb服务详解(含源代码,测试通过,注释) ——Emp的Dao层
2019-03-11
java实现人脸识别源码【含测试效果图】——Dao层(IUserDao)
2019-03-11
使用ueditor实现多图片上传案例——前台数据层(Index.jsp)
2019-03-11
ssm(Spring+Spring mvc+mybatis)——saveDept.jsp
2019-03-11