jsp +mysql+分页


 

第一步 标记 html
 
<div class="resultTitle">
  			<ul class="Ttt">
  				<li>姓名</li>
  				<li>电话</li>
  				<li>公司</li>
  			</ul>
  		<div class="cont" id="box">
  			<div id="resultList">
  			</div>
  			<div id="paginationbar" class="paginationbar"></div>
				<!--分页导航-->
				<div id="displayNum" class="displayNum"></div>
				<!--每页显示数目导航-->
			<div class="clear"></div>
		</div>
  		</div>


第二步 js脚本

 	function searchHistory(page,disR){
  		var fn = arguments.callee;
  		var req = "member_name="+$('#member_name').val()+'&mobile='+$('#mobile').val()+'&company_name='+$('#company_name').val() + '&page='+(page||1)+'&displayRecord='+(disR=disR||10);
  		$.post('/member/search.do', req, function(json) {
  			if(json.success === true){
				var $tbody = $('#resultList'), $box = $('#box');
				var html = '';
				var count 	= json.object.count,
				list 		= json.object.lists,
				p 			= json.object.page,
				pCount 		= json.object.pageCount;
				$.each(list,function(i,n){
					var text = "<ul>"+
					'<li>'+n.member_name+'</li>'+
					'<li>'+n.mobile+'</li>'+
					'<li>'+n.company_name+'</li>'+
					'</ul>';
					if(null != text && text != ""){
						html += text;
					}
				});
				$tbody.html(html);
				overColor($("#resultList").children("ul"));

				//分页
				var $pag=$box.find('.paginationbar'),$dis=$box.find('.displayNum');
				$.sysop.pagination.init($pag,p,pCount,10,function(num){
					fn(num,disR);
				});
				//显示数目
				$.sysop.pagination.displayNum($dis,disR,function(){
					fn(1,this.innerHTML.slice(0,-1));
				});

			}else{
				var msg = json.message;
				$(".error").text(msg);
			}
  	  	});
	}

  	$('.searchBtn').bind('click',function(){
			searchHistory(1,10, true);
	});

脚本中 内置的一些函数 可以在附件中找到


第三步  写Java方法

@MethodResourceDesc(name = "[data]搜索会员")
	@RequestMapping(value = "/member/search.do")
	@ResponseBody
	public Result getConsumerCreditRecordByUserId(HttpServletRequest request,HttpServletResponse response, Member entity){
		Result result = new Result();
		int pageSize = RequestHelper.getPageSize(request);
		if(0 == pageSize){
			pageSize = 20;
		}


		Map<String,Object> map = new HashMap<String,Object>();
		map.put("page", (RequestHelper.getPageIndex(request) - 1) * pageSize);
		map.put("pageSize", pageSize);
		map.put("member_name", entity.getMember_name());
		map.put("mobile",entity.getMobile() );
		map.put("company_name", entity.getCompany_name() );
		map.put("member_type", entity.getMember_type() );

		List<Member> list = memberService.searchMember(map);

		int allCount = (int)memberService.allCount(entity);

		PagingVO pagingObject = new PagingVO();
		pagingObject.setPageCount((allCount + pageSize) / pageSize);
		pagingObject.setPage(RequestHelper.getPageIndex(request));
		pagingObject.setCount(allCount);
		pagingObject.setLists(list);
		result.setCode(ResultCode.SUCCESS);
		result.setObject(pagingObject);

		return result;
	}
其中内置的一些方法 可以在附件中找到


第四部 mybatis 文件编写

<select id="allCount" parameterType="Member" resultType="long">
		<![CDATA[
			select count(*) from member m where 1=1
		]]>
			<if test="member_type != null and member_type != ''" >
			         <![CDATA[ and member_type = #{member_type}]]>
			</if>
	</select>


	<select id="searchMember" resultType="Member" parameterType="int">
		<![CDATA[
			select * from member where 1=1
		]]>

			<if test="member_name != null and member_name != ''" >
			         <![CDATA[and member_name like CONCAT('%',#{member_name},'%')]]>
			</if>
			<if test="mobile != null and mobile != ''" >
			         <![CDATA[and mobile like CONCAT('%',#{mobile},'%')]]>
			</if>
			<if test="company_name != null and company_name != ''" >
			         <![CDATA[and company_name like CONCAT('%',#{company_name},'%')]]>
			</if>
			<if test="member_type != null and member_type != ''" >
			         <![CDATA[ and member_type = #{member_type}]]>
			</if>

			<![CDATA[  limit #{page} ,#{pageSize}]]>
	</select>


第五步  编写DAO  实现类

public List<Member> searchMember(Map<String,Object> map);

@Override
	public List<Member> searchMember(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return  memberDao.searchMember(map);
	}


上传的 文件 分别是 附件 和 项目 效果图在桌面

你可能感兴趣的:(mysql)