myBatis 分页:
mybatis sql脚本:
<select id="getAllHnbPage" resultType="hashmap" parameterType="pageInfo">
<![CDATA[
select * from view_HNBIdentifier order by hnbIdentifier asc limit #{startNum}, #{pageSize}
]]>
</select>
<select id="getAllHnbCount" resultType="int">
<![CDATA[
select count(*) from view_HNBIdentifier
]]>
</select>
DAO方法:
public List<HashMap<String, Object>> getAllHnbPage(PageInfo page);
serviceImpl:
public List<HnbInfo> getHnbListPage(PageInfo page)
{
List<HnbInfo> hnbList = new ArrayList<HnbInfo>();
// 获取所有的基站信息
List<HashMap<String, Object>> mapList = hnbDao.getAllHnbPage(page);
// 记录总数
int count = hnbDao.getAllHnbCount();
page.setTotalCount(count);
if (page.getCurrentPage() > page.getTotalSize())
{
return getHnbListPage(Global.createPage(page));
}
else
{
// 循环结果集,填充基站集合
HnbInfo hnb = null;
for (HashMap<String, Object> map : mapList)
{
hnb = new HnbInfo();
hnb.setInternetID(map.get("internetID").toString());
hnb.setHnbIdentifier(map.get("hnbIdentifier").toString());
if (null != map.get("hnbName"))
{
hnb.setHnbName(map.get("hnbName").toString());
}
hnb.setSerialNumber(map.get("serialNumber").toString());
if (null != map.get("locationPathNo"))
{
hnb.setLocationPathNo(Integer.parseInt(map.get("locationPathNo").toString()));
}
if (null != map.get("distancetoPathAccess"))
{
hnb.setDistancetoPathAccess(Integer.parseInt(map.get ("distancetoPathAccess").toString()));
}
hnbList.add(hnb);
}
return hnbList;
}
}
controller 方法:
@RequestMapping("/allHnb")
public ModelAndView getAllHnb(PageInfo page, HttpServletRequest request)
{
try
{
List<HnbInfo> hnbList = hnbService.getHnbListPage(page);
request.setAttribute("hnbList", hnbList);
request.setAttribute("page", page);
}
catch (Exception e)
{
logger.error(Global.LOG_EXCEPTION_NAME, e);
}
return new ModelAndView("config/hnb_list");
} |