zoukankan      html  css  js  c++  java
  • Mybatis分页插件

    mybatis配置

       	<!-- mybatis分页插件 -->
    	<bean id="pagehelper" class="com.github.pagehelper.PageHelper">
    		<property name="properties">
    			<props>
    				<prop key="offsetAsPageNum">true</prop>
    				<prop key="rowBoundsWithCount">true</prop>
    				<prop key="pageSizeZero">true</prop>
    				<prop key="reasonable">false</prop>
    				<prop key="supportMethodsArguments">false</prop>
    			</props>
    		</property>
    	</bean>
    
          <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
            <property name="dataSource" ref="dataSource" />  
            <!-- 自动扫描mapping.xml文件 -->  
            <property name="mapperLocations" value="classpath:com/*/mapping/*.xml"></property>  
            <property name="plugins">
    			<list>
    				<!-- <ref bean="offsetLimitIntercepter" /> -->
    				<ref bean="pagehelper" />
    			</list>
    		</property>
        </bean>  
    

      java 类,写一个class继承这个抽象类

    public abstract class AbstractPageForm<T extends AbstractPageForm<T>> implements Serializable {
    
    	private static final long serialVersionUID = 1L;
    
    	/**
    	 * @Description 页码为首页
    	 */
    	@DefaultValue("1")
    	@QueryParam("pageNum")
    	protected int pageNum = 1;
    	/**
    	 * @Description 每页显示数量,默认为10
    	 */
    	@DefaultValue("10")
    	@QueryParam("pageSize")
    	protected int pageSize = 10;
    
    	public int getPageNum() {
    		return pageNum;
    	}
    
    	public void setPageNum(int pageNum) {
    		this.pageNum = pageNum;
    	}
    
    	public int getPageSize() {
    		return pageSize;
    	}
    
    	public void setPageSize(int pageSize) {
    		this.pageSize = pageSize;
    	}
    
    	/**
    	 * @Title enablePaging
    	 * @Description 启用分页
    	 * @return
    	 */
    	@SuppressWarnings("unchecked")
    	public final T enablePaging() {
    		PageHelper.startPage(pageNum, pageSize);
    		return (T) this;
    	}
    
    
    }
    

      mapper.xml   (CourseForm继承了AbstractPageForm的抽象类)

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.*.*DAO" >
      <resultMap id="BaseResultMap" type="com.*.Class" >
        <id column="id" property="id" jdbcType="INTEGER" />
       
      </resultMap>
    
      
        <select id="selectCourseList" resultMap="BaseResultMap" parameterType="com.*.form.CourseForm" >
        select 
        <include refid="Base_Column_List" />
        from TABLE_NAME
      </select>
      
    </mapper>
    

      分页类示例:

    @Override
    	public PageInfo<Class> queryList(CourseForm courseForm) {
            //Class需要替换成自己的类 List<Class> selectList = organizationDAO.selectList(courseForm.enablePaging()); PageInfo<Class> pageInfo = new PageInfo<Class>(selectList); return pageInfo; }

      pageInfo,POM配置

    		
    		<dependency>
    		    <groupId>com.github.pagehelper</groupId>
    		    <artifactId>pagehelper</artifactId>
    		    <version>4.1.5</version>
    		</dependency>
    

      

  • 相关阅读:
    sql字符串函数(转)
    sqlserver 导入/导出Excel
    SelectSingleNode和SelectNodes区别
    iOS sqlite 的各种操作
    iOS 自定义的对象类型的解档和归档
    开放-封闭原则(OCP)开-闭原则 和 依赖倒转原则,单一职责原则
    iOS UITableView , UITableViewController ,UITableViewCell实现全国各省市遍历,选择相应的地区
    iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值
    iOS中的事件传递和响应者链条
    iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
  • 原文地址:https://www.cnblogs.com/tietazhan/p/5985542.html
Copyright © 2011-2022 走看看