日期:2014-05-18  浏览次数:20749 次

mybatis分页(菜鸟求教)
我是连接mysql数据库,
假定代码是select * from userInf limit start , 10
也就是,传入start,然后就得到相对应的List<UserInf>
------------------
我的代码如下:
UserInfMapper.xml
  <resultMap id="BaseResultMap" type="model.UserInf" >
    <id column="user_id" property="userId" jdbcType="DECIMAL" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="user_passwd" property="userPasswd" jdbcType="VARCHAR" />
  </resultMap>

<select id="findByLimit" parameterType="java.lang.Integer" resultMap="BaseResultMap">
       select * from  from userInf limit #{start,jdbcType=DECIMAL}
      </select>

但是出了个问题,start是不存在于任何一张表的数据,
那么,我该在UserInfMapper.xml中怎么写,才能把start传入mybatis中?
-----------
另附:我所有的mybatis代码都是写在.xml中,然后直接java映射就完事儿了。
求指教!
------解决方案--------------------
你表达的意思有点模糊。能重新解释下么
就在调用的时候把start传进去的。。
------解决方案--------------------
你把分页所要的数据存存进一个对象中.如pageModle.  然后在调用mapper时传进去. 在XML里直接#{pageModle.pageIndex}就行了.(也就是你的start)
------解决方案--------------------
package com.bing.hrm.common;
/**
 * 分页实体
 */
public class PageModel {
/** 默认每页显示的记录条数 */
private static final int PAGE_SIZE = 2;

/** 当前页码 */
private int pageIndex;
/** 每页显示的数量 */
private int pageSize;
/** 总记录条数 */
private int recordCount;

/** setter and getter method */
public int getPageIndex() {
//当前页码不能小于1
this.pageIndex = pageIndex< 1 ? 1 : pageIndex;
//不能大于总页
int totalPage = this.getRecordCount()%this.getPageSize() == 0 ?
this.getRecordCount()/this.getPageSize() :
(this.getRecordCount()/this.getPageSize())+1;
this.pageIndex = this.pageIndex > totalPage ? totalPage : this.pageIndex;
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public int getPageSize() {
return pageSize <= 0 ? PAGE_SIZE : pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}

// limit 第一个?的值
public int getStartRow(){
return (this.getPageIndex() - 1) * this.getPageSize();
}
}

------解决方案--------------------
这还不简单,实体类(UserInf)中加个start属性就可以了,记得getset它