基于ssm,Oracle,freemark的分页

page类

package mock.model;

import java.util.List;

public class Page<T> {
	//已知数据
	private int current=3;//当前页,默认为3
	
	private int numPerPage=15;//每页多少条,默认为15
	
	private int totalCount;// 总记录数,查数据库
	//需要计算得到的
	private int totalPage;//总页数

	private List<Mesg> Mesgs;//页面显示的记录
	private int start;
	private int end;
	public int getCurrent() {
		return current;
	}
	public void setCurrent(int current) {
		this.current = current;
	}
	public int getNumPerPage() {
		return numPerPage;
	}
	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public List<Mesg> getMesgs() {
		return Mesgs;
	}
	public void setMesgs(List<Mesg> mesgs) {
		Mesgs = mesgs;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getEnd() {
		return end;
	}
	public void setEnd(int end) {
		this.end = end;
	}
	public Page(){}
	public Page(int totalCount,int current){
		this.totalCount=totalCount;
		this.current=current;
		if(this.totalCount%this.numPerPage==0){
			this.totalPage=this.totalCount/this.numPerPage;
		}else{
		this.totalPage=this.totalCount/this.numPerPage+1;
		}
		this.start=1;
		this.end=5;
		if(this.totalPage<5){
			this.end=this.totalPage;
		}
		else{
			this.start=this.current-2;
			this.end=this.current+2;
			if(this.start<=0){
				this.start=1;
				this.end=5;
			}
			if(this.end>this.totalPage){
				this.end=this.totalPage;
				this.start=this.end-5;
			}
		}
	
	}
	
	
	
	
}

freemark页面

<#list mesgList as mesg>
	    <tr>
	        <td><button onClick="dealMsg(this)">${mesg.msgNo}</button></td>
	        <td>${mesg.msgName}</td>
	        <td>${mesg.msgSerl}</td>
	        <td>${mesg.orgMsgSerl}</td>
	        <td>${mesg.comSerl}</td>
	        <td>${mesg.comSerlRef}</td>
	        <td style="display:none;">${mesg.transType}</td>
	        <td>${mesg.transTypeStr}</td>
	        <td>${mesg.sendDate}</td>
	        <td>${mesg.msgStateName}</td>         
	        
	    </tr>
	    </#list>
<div>
 共有${page.totalCount}条记录,共${page.totalPage}页,现在是第${page.current}页
  <a href="javascript:indexPage()">首页</a>
  <#if page.current!=1>
  <a href="javascript:lastPage(${page.current-1})">上一页</a>
  </#if>
  <#list page.start..page.end as i>
    <#if i==page.current>
      ${i}
     <#else>
      <a href="javascript:lastPage(${i})">${i}</a>
      </#if>
  </#list>
  <#if page.current!=page.end>
    <a href="javascript:lastPage(${page.current+1})">下一页</a>
  </#if>
  <a href="javascript:lastPage(${page.totalPage})">尾页</a>
  

controller层

@RequestMapping("/list")
	public String list(ModelMap map, Model model, HttpServletRequest request) {
		String scheme = request.getScheme();
		String serverName = request.getServerName();
		int port = request.getServerPort();
		String path = request.getContextPath();
		String basePath = scheme + "://" + serverName + ":" + port + path;
		System.out.println(basePath);
		request.setAttribute("basePath", basePath);
		long msgState = -1;
		String msgType = request.getParameter("msgtype");
		String queryMsgNo = request.getParameter("queryMsgNo");
		MesgQueryVo vo=new MesgQueryVo();
		Page<Mesg> pageBean=new Page<Mesg>();
		int pageNum=pageBean.getCurrent();
				if (request.getParameter("pageNum") != null&&!"".equals(request.getParameter("pageNum"))){
					pageNum = Integer.parseInt(request.getParameter("pageNum"));
					
				}
		vo.setPageNum(pageNum);
		vo.setNumPerPage(pageBean.getNumPerPage());
			

		if (request.getParameter("msgState") != null && !"".equals(request.getParameter("msgState"))) {
			msgState = Long.parseLong(request.getParameter("msgState"));
		}

		//Map<String, Object> param = new HashMap<String, Object>();
		
		if (request.getParameter("msgState") != null && !"".equals(request.getParameter("msgState"))) {
			vo.setMsgState(msgState);
		}
		
		
		if (StringUtils.isNotEmpty(msgType)) {
			msgType = msgType.toUpperCase();
			vo.setMsgtype(msgType);
		}
		if(StringUtils.isNotEmpty(queryMsgNo)){
			vo.setQueryMsgNo(queryMsgNo);
		}
		
	   
		Page page = mesgService.findByPage(vo);
		List<Mesg> mesgList=page.getMesgs();
		if (mesgList != null && mesgList.size() > 0) {
			for (int i = 0; i < mesgList.size(); i++) {
				if (mesgList.get(i).getMsgState() != null && mesgList.get(i).getMsgState() >= 0) {
					String msgStateName = MessageStatus.getResult(mesgList.get(i).getMsgState()).getDescription();
					mesgList.get(i).setMsgStateName(msgStateName);
				}

				if (mesgList.get(i).getMsgNo() != null && !"".equals(mesgList.get(i).getMsgNo())) {
					MesgType type = null;
					try {
						type = (MesgType) MesgType.class
								.getField(mesgList.get(i).getMsgNo().substring(0, 7).replace(".", "")).get(null);
						mesgList.get(i).setMsgName(type.getDescription());
					} catch (Exception e) {
						System.err.println("查询异常,数据中存在报文类型空的");
					}

				}

				mesgList.get(i).setTransTypeStr(getTransTypeStr(String.valueOf(mesgList.get(i).getTransType())));
			}
		}
       map.addAttribute("page", page);
		map.addAttribute("mesgList", mesgList);
		map.addAttribute("msgState", msgState);
		map.addAttribute("msgType", msgType);
		map.addAttribute("queryMsgNo", queryMsgNo);
		return "/mesg/view/list";
	}

service层

public Page findByPage(MesgQueryVo vo) {
		int numPerPage=vo.getNumPerPage();
		int pageNum=vo.getPageNum();
		
		
		int totalCount = userMapper.getItemsCount(vo);
		Page page=new Page(totalCount,pageNum);
		
		
		if(page.getEnd()<3){
			page.setCurrent(1);
			vo.setPageNum(1);
		}
				
	
		List list = userMapper.findByPage(vo);
		page.setMesgs(list);//设置当前页面数据 
		
		return page;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值