package cn.tsjinrong.fastfile.util;





/**

 * @ClassName: Page

 * @Description: TODO(分页组件的父类,用来封装分页的 通用内容和逻辑)

 * @author zhanghaiyang

 * @date 2016年1月14日 下午12:37:55

 * @Copyright © 2016上海通善互联网金融信息服务有限公司

 */

public class Page {





// 用户输入的分页条件

private int currentPage = 1; // 当前页

private int pageSize = 15; // 每页最大行数





// 用于实现分页SQL的条件,是根据用户输入条件计算而来的

private int begin;

private int end;





// 自动计算出的总行数

private int rows;

// 根据总行数计算总页数,然后将总页数输出给页面

private int totalPage;





public int getRows() {

return rows;

}





public void setRows(int rows) {

this.rows = rows;

}





public int getTotalPage() {

// 根据总行数,计算总页数

if (rows % pageSize == 0) {

totalPage = rows / pageSize;

} else {

totalPage = rows / pageSize + 1;

}

return totalPage;

}





public void setTotalPage(int totalPage) {

this.totalPage = totalPage;

}





public int getBegin() {

// 在mapper.xml使用begin属性时,对其进行计算

begin = (currentPage - 1) * pageSize;

return begin;

}





public void setBegin(int begin) {

this.begin = begin;

}





public int getEnd() {

// 在mapper.xml使用end属性时,对其进行计算

end = currentPage * pageSize + 1;

return end;

}





public void setEnd(int end) {

this.end = end;

}





public int getCurrentPage() {

return currentPage;

}





public void setCurrentPage(int currentPage) {

this.currentPage = currentPage;

}





public int getPageSize() {

return pageSize;

}





public void setPageSize(int pageSize) {

this.pageSize = pageSize;

}





}



public ModelAndView findVideosByPage(HttpServletRequest request, HttpServletResponse response, FileProperties fp) {





ModelAndView model = new ModelAndView("/video/video_list");

Map<String, Object> params = new HashMap<String, Object>(3);

if (StringUtils.isNotBlank(fp.getBusiId())) {

params.put("busiId", fp.getBusiId());

}

if (StringUtils.isNotBlank(fp.getApplyName())) {

params.put("applyName", fp.getApplyName());

}

if (fp.getApplyDateStart() != null && StringUtils.isNotBlank(fp.getApplyDateStart())) {

params.put("applyDateStart", DateUtil.parseDate(fp.getApplyDateStart()));

} else {

params.put("applyDateStart", DateUtil.addDay(new Date(), -7));

}

if (fp.getApplyDateEnd() != null && StringUtils.isNotBlank(fp.getApplyDateEnd())) {

params.put("applyDateEnd", DateUtil.parseDate(fp.getApplyDateEnd()));

} else {

params.put("applyDateEnd", DateUtil.format(new Date()));

}

fp.setRows(fastfileVideoService.selectRows(params));

model.addObject("fastfileVideoInfoPage", fp);

List<FastfileVideoInfo> fastfileVideoInfos = fastfileVideoService.selectByPage(fp);

model.addObject("fastfileVideoInfos", fastfileVideoInfos);

model.addObject("applyDateStart", DateUtil.format(DateUtil.addDay(new Date(), -7)));

model.addObject("applyDateEnd", DateUtil.format(new Date()));

return model;

}



<select id="selectByPage" resultMap="BaseResultMap" parameterType="cn.tsjinrong.fastfile.util.FileProperties">

select

<include refid="Base_Column_List" />

from fastfile_video_info where 1=1

<if test="busiId != null and busiId !=''">

and busi_id = #{busiId,jdbcType=VARCHAR}

</if>

<if test="applyName != null and applyName !=''">

and apply_name=#{applyName,jdbcType=VARCHAR}

</if>

<if test="applyDateStart != null and applyDateStart !=''">

and apply_date &gt;= #{applyDateStart,jdbcType=DATE}

</if>

<if test="applyDateEnd != null and applyDateEnd !=''">

and apply_date &lt;= #{applyDateEnd,jdbcType=DATE}

</if>

and del_flag = 0

order by apply_date desc limit #{beginRow},#{pageSize}

</select>

MyBatis学习总结(12)——Mybatis+Mysql分页查询的更多相关文章

  1. MyBatis学习总结(七)——Mybatis缓存(转载)

      孤傲苍狼 只为成功找方法,不为失败找借口! MyBatis学习总结(七)--Mybatis缓存 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的 ...

  2. 【转】MyBatis学习总结(一)——MyBatis快速入门

    [转]MyBatis学习总结(一)——MyBatis快速入门 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC ...

  3. 【转】MyBatis学习总结(七)——Mybatis缓存

    [转]MyBatis学习总结(七)——Mybatis缓存 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualC ...

  4. 转:MyBatis学习总结(Mybatis总结精华文章)

    http://www.cnblogs.com/xdp-gacl/tag/MyBatis%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/ 当前标签: MyBatis学习总结   ...

  5. Mybatis学习系列(五)关联查询

    前面几节的示例基本都是一些单表查询,实际项目中,经常用到关联表的查询,比如一对一,一对多等情况.在Java实体对象中,一对一和一对多可是使用包装对象解决,属性使用List或者Set来实现,在mybat ...

  6. Mybatis学习笔记12 - 动态sql之choose(when otherwise)标签

    choose (when, otherwise):分支选择:带了break的swtich-case 示例代码: 接口定义: package com.mybatis.dao; import com.my ...

  7. MyBatis 学习记录5 MyBatis的二级缓存

    主题 之前学习了一下MyBatis的一级缓存,主要涉及到BaseExecutor这个类. 现在准备学习记录下MyBatis二级缓存. 配置二级缓存与初始化发生的事情 首先二级缓存默认是不开启的,需要自 ...

  8. MyBatis学习总结(一)——MyBatis快速入门(转载)

    本文转载自http://www.cnblogs.com/jpf-java/p/6013537.html MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了 ...

  9. MyBatis学习总结(一)——MyBatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  10. MyBatis学习笔记(一)——MyBatis快速入门

    转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4261895.html 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优 ...

随机推荐

  1. Please ensure that adb is correctly located at &#39;D:\Android\android-sdk\platform-tools\adb.exe&#39; and

    1.启动任务管理器 2.找到百度安全组件杀掉进程. 3.一般都是组件给禁止了.

  2. legend---六、php脚本变量的生命周期是怎样的

    legend---六.php脚本变量的生命周期是怎样的 一.总结 一句话总结:应该是脚本结束变量的生命周期就完了 1.外部js找不到元素是怎么回事? 1 function myDailyTaskFin ...

  3. Centos7 网络出错(failed to start LSB: Bring up/down networking )

    这是我更换了VM虚拟机内存,重启后无法连接网络. 然后这是因为NetworkManager.service这个程序造成 解决方法: systemctl disable NetworkManager.s ...

  4. centos7 ssh免口令认证登录

    摘要:centos7, xshell, 公钥,  ssh ssh登录方式有口令认证登录和密钥认证登录 接下来本次介绍是ssh密钥登录方式 (1)产生公钥 (2)将公钥放置到centos7的(/root ...

  5. 如何把本地的项目推送到github上面去

    前题:本地已经建好了项目,但电脑上没有安装git  (windows 系统) 1.首页从网上下载git 并安装. 2.进入项目所在的文件夹,右键鼠标 3.新建.gitignore文件 touch .g ...

  6. JAVA工程命名规范

    Java推荐的包声明命名约定是反向域名. 例如 - com.abysm.myproject

  7. HDU 1668 Islands and Bridges

    Islands and Bridges Time Limit: 4000ms Memory Limit: 65536KB This problem will be judged on HDU. Ori ...

  8. C++中父类的虚函数必需要实现吗?

    一.情景 C++中父类的虚函数必需要实现吗? class Vir{ public: virtual void tryVirtual(); }; class CVir:public Vir{ publi ...

  9. 图解hdu5301Buildings

    这个题就是给出一个大矩形n*m.当中有个1*1的小格子不能被占用,然后要你用非常多小矩形去填满.问小矩形的最小最大面积是多少. 显然小矩形必定是1*x的最好,毕竟i*x,若i>1则还是能够拆成非 ...

  10. Android java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses

    项目开发快到尾声,突然发现之前一个模块莫名其妙的奔溃了,我的内心也是奔溃的.以前一直都是好好的,也没去动过它,为啥会出现这样的问题呢? 下面我会根据自己的理解来看待问题 android是怎么根据id查 ...