EasyUI-datagrid 实现分页详细(mybatis)

2 篇文章 0 订阅
1 篇文章 0 订阅

说明:

没有运用方便的pagehelper插件,由于没系统学过ssm框架,
配置文件还不怎么摸得着头脑,赶着弄毕业设计

jsp

<div>
	<table id="carCategoryTable" style="width: 100%;">
	</table>
</div>

js

$(function(){
	$('#carCategoryTable').datagrid({
	    url:'<c:url value="ListForUser.action"/>',
	    queryParams:getParams(),//提交参数
	    toolbar:'#carCategoryToolbar',//表头工具栏
	    pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    pageList:[10, 20, 30, 40], 
	    fitColumns:true,
	    //checkOnSelect:true,
	    selectOnCheck:false,
	    sortName: 'userName',
	    sortOrder: 'asc',
	    remoteSort: false,
	    singleSelect:false,
	    //fitColumns:false,
	    //multiSort:true,
	    rownumbers:true,
	    //checkOnSelect:true,
	    striped:true,
	    //singleSelect:false,
	    //singleSelect:true,
	    columns:[[
			{field:'studentId',title:'',formatter: function(value,row,index){
				return '<input name="studentId" type="checkbox" value="'+value+'" />';
			}},
			{field:'userName',title:'账户',width:100,align:'center',sortable:true},
			{field:'cnName',title:'名字',align:'center',width:100},
			{field:'sex',title:'性别',align:'center',width:100},
			{field:'college',title:'学院',align:'center',width:150},
			{field:'theClass',title:'班级',align:'center',width:100},
			{field:'grade',title:'年级',align:'center',width:100},
			{field:'disable',title:'账户禁用',align:'center',width:50,editor:{type:'checkbox',options:{on:1,off:0}},formatter : function(value, row, index) {
				if(value==0)
					 return '禁用';
					else
					return '启用';
				},}
	    ]],
	    onClickRow:function(index,row){
	    $("input[type=checkbox]").val([row.studentId]).attr("checked",true);
	    }
	});
});

controller

	@RequestMapping(value="/ListForUser",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> ListForUser(HttpServletRequest request,Integer page,Integer rows,User record){
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			page=page==null?1:page;
			rows=rows==null?10:rows;
			//PageHelper.startPage(pageNum, pageSize);
			map = userService.selectUserList(page,rows,record);
			//PageInfo<User> paGe = new PageInfo<User>(user);
			//map.put("total", user.size());
			//map.put("rows", paGe.getList());
			//map.put("pageNum", new Integer(paGe.getPageNum()));//
			//map = ListPage.setPageParamToMap(paGe);
		} catch (Exception e) {
			// TODO: handle exception
			LogUtil.errorLog(e);
		}
		return map;
	}

service

	@Override
	public Map<String, Object> selectUserList(int pageNum, int pageSize, User record) {
		Map<String, Object> map = new HashMap<String, Object>();
		// TODO Auto-generated method stub
		//PageHelper.startPage(pageNum, pageSize);
		List<User> userSize = userMapper.selectUserListSize(record);
		int pageSizez;
		if(((pageSize*pageNum)-userSize.size())<0){
			pageSizez = pageSize;
		}else{
			pageSizez = userSize.size()-(10*(pageNum-1));
		}
		List<User> user = userMapper.selectUserList(pageNum*pageSize-pageSize,pageSizez,record);
		//PageInfo<User> paGe = new PageInfo<User>(user);
		//return ListPage.setPageParamToMap(paGe);
		
		map.put("rows", user);
		map.put("total",userSize.size());
		return map;
	}

mapper.java

public interface UserMapper {
	List<User> selectUserList(@Param("start") int pageNum, @Param("count") int pageSize,@Param("user") User record);
    List<User> selectUserListSize(User record);
}

mapper.xml

<select id="selectUserList" parameterType="com.icss.cup" resultMap="BaseResultMap">
  	select 
  	<include refid="Base_Column_List"/>
  	from user
  	<where>
  		<if test="user.userName !='' and user.userName != null">
  			and USER_NAME like CONCAT(CONCAT('%',#{user.userName}),'%')
  		</if>
  		<if test="user.cnName !='' and user.cnName != null">
  			and CN_NAME like CONCAT(CONCAT('%',#{user.cnName}),'%')
  		</if>
  		<if test="user.college != null and user.college != ''">
  			and COLLEGE like CONCAT(CONCAT('%',#{user.college}),'%')
  		</if>
  		<if test="user.grade != '' and user.grade != null">
  			and GRADE like CONCAT(CONCAT('%',#{user.grade}),'%')
  		</if>
  		<if test="user.storiedBuilding != null">
  			and STORIED_BUILDING = #{user.storiedBuilding,jdbcType=VARCHAR}
  		</if>
  		<if test="start!=null and count!=null">
  			limit #{start},#{count}
  		</if>
  	</where>
  </select>
  
  <select id="selectUserListSize" parameterType="com.icss.cup.pojo.User" resultMap="BaseResultMap">
  	select 
  	<include refid="Base_Column_List"/>
  	from user
  	<where>
  		<if test="userName !='' and userName != null">
  			and USER_NAME like CONCAT(CONCAT('%',#{userName}),'%')
  		</if>
  		<if test="cnName !='' and cnName != null">
  			and CN_NAME like CONCAT(CONCAT('%',#{cnName}),'%')
  		</if>
  		<if test="college != null and college != ''">
  			and COLLEGE like CONCAT(CONCAT('%',#{college}),'%')
  		</if>
  		<if test="grade != '' and grade != null">
  			and GRADE like CONCAT(CONCAT('%',#{grade}),'%')
  		</if>
  		<if test="storiedBuilding != null">
  			and STORIED_BUILDING = #{storiedBuilding,jdbcType=VARCHAR}
  		</if>
  	</where>
  </select>

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值