springboot分页查询接口

Mapper:

分页查询意向客户

@Select("SELECT * FROM t_customer WHERE intention = 1 and periods = #{arg0} LIMIT #{arg1},#{arg2}")

publicList getIntentionByPage(String periods,intstart,intsize);

Service:

publicList getIntentionByPage(String periods,intstart,intsize)

{

returncustomerMapper.getIntentionByPage(periods,start,size);

}

Controller:

@RequestMapping("/customerIntentionByPage")

publicList getIntentionByPage(Page page )

{

page.initNum();

returncustomerService.getIntentionByPage(page.getPeriods(),page.getStart(),page.getSize());

}

封装的Page:

public classPage

{

private intsize;

private intpageNum;

privateStringperiods;

private intstart;

private intend;

private intcount;

public intgetCount()

{

returncount;

}

public voidsetCount(intcount)

{

this.count= count;

}

public intgetSize()

{

returnsize;

}

public voidsetSize(intsize)

{

this.size= size;

}

public intgetPageNum()

{

returnpageNum;

}

public voidsetPageNum(intpageNum)

{

this.pageNum= pageNum;

}

publicString getPeriods()

{

returnperiods;

}

public voidsetPeriods(String periods)

{

this.periods= periods;

}

public intgetStart()

{

returnstart;

}

public voidsetStart(intstart)

{

this.start= start;

}

public intgetEnd()

{

returnend;

}

public voidsetEnd(intend)

{

this.end= end;

}

public voidinitNum()

{

if(pageNum>=1&&size>0)

{

//从第几条开始

start= ((pageNum-1) *size) ;

//在第几条结束

end= ((pageNum-1) *size) +size;

}

}

}

在浏览器中输入地址/periods=?&pageNum

=?&size=?

参数意思是:第几期,第几页,每一页显示几条数据

你可能感兴趣的:(springboot分页查询接口)