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. springboot结合mybatis使用pageHelper插件进行分页查询

    1.pom相关依赖引入 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...

  2. mysql 分页查询

    mysql,; : mysql,; -last. //如果只给定一个参数,它表示返回最大的记录行数目: mysql; 个记录行 ,n. 动态传参的分页查询 SELECT * FROM table LI ...

  3. mysql分页查询详解

    我们做的后端项目一般都会有admin管理端,当管理端将要展示数据的时候,就需要用到分页.所以分页的考查在面试中也相当多.在mysql中进行分页查询时,一般会使用limit查询,而且通常查询中都会使用o ...

  4. Java GUI+mysql+分页查询

    1.要求 : 创建一个学生信息管理数据库 2.实现分页查询 代码如下: a)学生实体类: /** * @author: Annie * @date:2016年6月23日 * @description: ...

  5. Mysql分页查询性能分析

    [PS:原文手打,转载说明出处,博客园] 前言 看过一堆的百度,最终还是自己做了一次实验,本文基于Mysql5.7.17版本,Mysql引擎为InnoDB,编码为utf8,排序规则为utf8_gene ...

  6. MySql分页查询慢|这里告诉你答案

    一.背景 我们在开发的过程中使用分页是不可避免的,通常情况下我们的做法是使用limit加偏移量:select * from table where column=xxx order by xxx li ...

  7. MySQL分页查询性能优化

    当需要从数据库查询的表有上万条记录的时候,一次性查询所有结果会变得很慢,特别是随着数据量的增加特别明显,这时需要使用分页查询.对于数据库分页查询,也有很多种方法和优化的点.下面简单说一下我知道的一些方 ...

  8. MySQL分页查询大数据量优化方法

    方法1: 直接使用数据库提供的SQL语句 语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N适应场景: 适用于数据量较少的情况(元组百/千级)原因/缺点: ...

  9. mysql分页查询语法

    一.limit语法 SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset LIMIT 子句可以被用于强制 SELECT 语句返回指 ...

随机推荐

  1. Team Homework #3 软件工程在北航——IloveSE

    任务要求: 采访以前上过北航  (计算机系/软件学院) 软件工程课的同学.现在上研/工作的也可以. 采访问题如下:* 平均每周花在这门课上的时间 (包括上课/作业/上机)    * 平均写的代码总行数 ...

  2. 微软Hololens学院教程-Hologram 220-空间声音(Spatial sound )【本文是老版本,与最新的微软教程有出入】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦! 原文链接https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...

  3. 向Array中添加选择排序

    选择排序思路 在无序区中选出最小的元素,然后将它和有序区的第一个元素交换位置. 选择排序实现 Function.prototype.method = function(name, func){ thi ...

  4. Careercup - Google面试题 - 4847954317803520

    2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...

  5. 【Minimum Depth of Binary Tree】cpp

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

  6. JavaScript 关于变量作用域的一道面试题

    ShineJaie 原创,转载请注明出处. 昨晚在一个交流群里看到有位网友提了一个他的面试题求助答疑.刚好我也有看到,就对这个问题思考了一下,觉得这道题对理解 JavaScript 作用域还是很有帮助 ...

  7. python-操作mssql数据库

    准备工作: cmd 命令行下安装pymssql: pip install pymssql 查询的数据库如下: 代码如下: #coding=utf-8 import pymssql class MSSQ ...

  8. Visual Studio 2013

    1.How to hide reference counts in VS2013? Tools--> Options --> Text Editor --> All Language ...

  9. GS连接事件

    GS网络连接事件 //网络事件 //这个事件是在libevent里面的收到的事件就是在那个listen里面,就是客户端打开,服务器收到通知 link_stat stat = (link_stat)rP ...

  10. HDU1014Uniform Generator

    Uniform Generator Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   ...