JQuery分页插件的使用

写了太多的查询语句,结果由于一开始没有加分页功能,导致后期返工。一哥们介绍的一款插件,让我瞬间从冬天来到春天。JavaWeb项目,采用SSM框架,一下送上部分实现代码。
以下为实体类代码

public class LCar{
private String cpage;
private String pageSize;;
private String rows;
private int totalpage;
private int beginIndex;
private int endIndex;
private List list;

public void setCpage(String cpage) {
this.cpage = cpage;
}

/**
* 获取当前页数
*
* @return
*/
public int getCpage() {
int _cpage = 1;
if (cpage != null) {
try {
_cpage = Integer.parseInt(cpage);
} catch (Exception ex) {
}

}
return _cpage;
}

public void setPageSize(String pageSize) {
this.pageSize = pageSize;
}

/**
* 每页多少条
*
* @return
*/
public int getPageSize() {
int _pageSize = 6;
if (pageSize != null) {
try {
_pageSize = Integer.parseInt(pageSize);
} catch (Exception ex) {
}

}
return _pageSize;
}

/**
* 获取当前页数
*
* @return
*/
public int getBeginIndex() {
int _beginIndex = (getCpage() - 1) * getPageSize();
return _beginIndex;
}

public int getEndIndex() {
return endIndex;
}

public List getList() {
return list;
}

/**
* 获取总条数
*
* @return
*/
public int getRows() {
int _rows = 0;
if (rows != null) {
try {
_rows = Integer.parseInt(rows);
} catch (Exception ex) {
}
}
return _rows;
}

/**
* 共多少页
*
* @return
*/
public int getTotalpage() {
// 得到总条数
int _totalpage = 0;
int rows = getRows();
int pagesize = getPageSize();
if (rows % pagesize == 0) {
_totalpage = rows / pagesize;
} else {
_totalpage = rows / pagesize + 1;
}
return _totalpage;
}

public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}

public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}

public void setList(List list) {
this.list = list;
}

public void setRows(String rows) {
this.rows = rows;
}

public void setTotalpage(int totalpage) {
this.totalpage = totalpage;
}
}

xml中的sql语句配置

<!--查询车位的数量-->

<select>select count(*) from tb_car</select>

<!--查询车辆车辆信息-->

<select>select car_cid, car_area, car_price from tb_car</select>
<select>limit #{beginIndex},#{pageSize}</select>
</code>
service实现
<code lang="java">
public LCar selectNotice(LCar model) {
// TODO Auto-generated method stub
List list = lmandao.selAllCarInf(model);
model.setList(list);
String rows = lmandao.selAllCarCount();
model.setRows(rows);
return model;
}

页面配置


<h2>车位</h2> <table> <tr> <th>编号</th> <th>ְ面积</th> <th>ְ价钱</th> </tr> <#list allTeCar.list as emp > <tr style="background-color: #f1f1f1;"> <td>${emp['car_cid']}</td> <td>${emp['car_area']}</td> <td>${emp['car_price']}</td> </tr> </#list> </table> <div class="tcdPageCode"></div> <script type="text/javascript" src="/property/static/js/jquery-3.1.0.min.js"></script> <script type="text/javascript" src="/property/static/js/jquery.page.js"></script> <script> $(".tcdPageCode").createPage({ pageCount:${allTeCar.totalpage}, current:${allTeCar.cpage}, backFn:function(p){ window.location.href="/property/back/testcar?cpage="+p; } }); </script>

controller示例

@RequestMapping("/xx/test")
public testShow(LCar car, Model model){
LCar _car = null;
_car = selectNotice(car);
model.addAttribute("allTeCar",_car);
return "showCar";
}
0

发表评论