Mybatis逆向工程中的分页查询
1,对实体类的操作
在对应的Example类中添加属性,并提供set&get方法
private Integer limit;
private Long offset;
public Integer getLimit() {
return this.limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Long getOffset() {
return this.offset;
}
public void setOffset(Long offset) {
this.offset = offset;
}
2,前端页面接受数据
1)page第几页。。。
2)limit每页显示几条数据
在控制层对传来的分页参数进行处理
ReceiveThePaymentExample example = new ReceiveThePaymentExample();
//设置分页参数 page第几页 limit每页分几条
if(page == null || page <= 0) {
page = 1;
}
if(limit == null || limit <= 0) {
limit = 10;
}
//将limit封装到对应的example类中
example.setLimit(limit);
//offset为从第几个数据开始查询
Long offset = new Long((page-1)*limit);
example.setOffset(offset);
List<ReceiveThePayment> listRayment = receiveThePaymentService.selectByReceiveThePaymentExample(example);
查询出的“listRayment”为最终的结果
3,service层的操作
1)service接口
/**
* 描述:根据ReceiveThePaymentExample查找ReceiveThePayment
* @version 1.0
* @param ReceiveThePaymentExample
* @return List<ReceiveThePayment>
*/
public List<ReceiveThePayment> selectByReceiveThePaymentExample(ReceiveThePaymentExample receiveThePaymentExample);
2)service实现类
@Override
public List<ReceiveThePayment> selectByReceiveThePaymentExample(ReceiveThePaymentExample receiveThePaymentExample) {
// TODO Auto-generated method stub
return receiveThePaymentMapper.selectByExample(receiveThePaymentExample);
}
4,dao层和数据库sql的操作
1)mapper接口
List<ReceiveThePayment> selectByExample(ReceiveThePaymentExample example);
2)mapper.xml的sql查询
<select id="selectByExample" parameterType="xusage.crm.pojo.ReceiveThePaymentExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from crm_receive_the_payment
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
5,前端页面显示(layerUI)
<script>
layui.use([ 'table', 'form', 'laydate','upload'], function() {
var formUrl = null;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
var laydate = layui.laydate;
var $ = layui.$;
var $ = layui.jquery
,upload = layui.upload;
//加载表格数据
var tableload = layer.load(2);
table.render({
elem : '#payment', //指定原始表格元素选择器(推荐id选择器)
url : 'receivePayment/list',
cellMinWidth : 50,
cols : [ [
{
type : 'checkbox'
},
{
field : "date",
title : "导入时间"
},
{
field : "subordinate",
title : "上级合伙人",
templet : function(data){
if(data.subordinateCarrier!=null){
return str = '<a style="color:#178eb9;" href="javascript:" lay-event="customerDetail">' +data.subordinateCarrier.companyName + '</a>';
}else{
return str ='未添加上级合伙人';
}
},
},
{
field : "higherUp",
title : "上两级合伙人",
templet : function(data){
if(data.highCarrier!=null){
return str = '<a style="color:#178eb9;" href="javascript:" lay-event="customerDetail">' +data.highCarrier.companyName + '</a>';
}else{
return str ='未添加上两级合伙人';
}
},
},
{
field : "subordinateBenefit",
title : "分润金额",
templet : function(data){
return str =data.higherUpBenefit+data.subordinateBenefit;
},
},
{
fixed : 'right',
title : "操作",
align : 'center',
width : '15%',
toolbar : '#btnGroup'
}
] ],
loading : true //分页加载样式
,
page : true//是否开启分页
,
loading : true //分页加载样式
,
done : function() {
layer.close(tableload);
}
});
});
</script>