(1)controller
@RequestMapping("/findData")
@ResponseBody
public Object findPhoneList(String startDate,String endDate,String phone,Integer pageIndex,Integer rows){
System.out.println(startDate+"||"+endDate+"||"+phone+"||"+pageIndex+"||"+rows);
PageInfo phoneList = cdrVoiceService.findPhoneListService(startDate, endDate, phone, pageIndex, rows);
return phoneList;
}
(2)service
public PageInfo findPhoneListService(String startDate,String endDate,String phone,Integer pageIndex,Integer rows){
Integer min = (pageIndex - 1) * rows;
Integer max = pageIndex * rows;
startDate=startDate!=""&&startDate!=null ?startDate+" 00:00:00":startDate;
endDate=endDate!=""&&endDate!=null?endDate+" 23:59:59":endDate;
int count = fraudCdrDao.countData(startDate, endDate, phone);
List<PhoneInfo> phoneInfos=new ArrayList<>();
if(count>0){
phoneInfos = fraudCdrDao.listData(startDate, endDate, phone, max, min);
}
PageInfo pageInfo = new PageInfo();
pageInfo.setRows(phoneInfos);
pageInfo.setTotal(count);
return pageInfo;
}
(3)dao
@Select(" <script> " +
" select count(*) from phoneTable t " +
" <where>"+
" <if test='phone !=null and phone!=\"\"'>" +
" and t.phone like '%${phone}%'" +
" </if> " +
" <if test='startDate !=null and startDate!=\"\"'> " +
" and t.insert_time >= to_date('${startDate}','yyyy-mm-dd hh24:mi:ss') " +
" </if> " +
" <if test='endDate !=null and endDate!=\"\"'> " +
" and t.insert_time <= to_date('${endDate}','yyyy-mm-dd hh24:mi:ss') " +
" </if>" +
" </where>" +
" </script>")
int countData(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("phone") String phone);
@Select(" <script> " +
" select t2.id,t2.phone,trim(t2.phone_type) phone_type,to_char(t2.insert_time,'yyyy-mm-dd hh24:mi:ss') insert_time,t2.insert_user from (" +
" select t.*,ROWNUM rn from phoneTable t " +
" <where>" +
" <if test='max!=null and max!=\"\"'>" +
" and ROWNUM <= ${max}" +
" </if>"+
" <if test='phone !=null and phone!=\"\"'>" +
" and t.phone like '%${phone}%'" +
" </if> " +
" <if test='startDate !=null and startDate!=\"\"'> " +
" and t.insert_time >= to_date('${startDate}','yyyy-mm-dd hh24:mi:ss') " +
" </if> " +
" <if test='endDate !=null and endDate!=\"\"'> " +
" and t.insert_time <= to_date('${endDate}','yyyy-mm-dd hh24:mi:ss') " +
" </if>" +
" </where>)t2 " +
" <where>" +
" <if test='min !=null and min !=\"\"'>" +
" t2.rn > ${min}" +
" </if>" +
" </where>" +
" order by t2.insert_time desc" +
" </script>")
List<PhoneInfo> listData(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("phone") String phone,@Param("max") Integer max,@Param("min") Integer min);
(4)PageInfo类:
import java.io.Serializable;
import java.util.List;
public class PageInfo<T> implements Serializable {
private Integer total;
private List<T> rows;
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
(5)分页sql理论依据: