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();
@Override
public 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;
}
@Override
public 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;
}
@Override
public 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;
}
@Override
public 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;
}
@Override
public 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;
}
@Override
public Page getHouseInfoByDymanic(HouseCondition housec, int pageIndex) {
Page page = new Page();
page.setPageIndex(pageIndex);
int reCount = reCount(housec);
page.setRecord(reCount);
List
houseList = 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;
}
@Override
public Page getHouseInfo() {
SqlSession session = MybatisUtil.getSession();
List
housel = session.selectList(BASE_MAPPINGS + "getHouseInfo");
Page page = new Page();
page.setHouseList(housel);
return page;
}
@Override
public 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;
}

}

上一篇:Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
下一篇:Mybatis+mysql动态分页查询数据案例——房屋信息的接口(IHouseDao)

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月16日 00时03分19秒