说明:
没有运用方便的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 \'禁用\';elsereturn \'启用\';},}]],onClickRow:function(index,row){$(\"input[type=checkbox]\").val([row.studentId]).attr(\"checked\",true);}});});
controller
@RequestMapping(value=\"/ListForUser\",method=RequestMethod.POST)@ResponseBodypublic 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 exceptionLogUtil.errorLog(e);}return map;}
service
@Overridepublic 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>