ibatis spring struts 简易分页显示,功能简单

下面为查询所显示的分页,关键技术在:1、只从数据库读取指定数量的数据

                                                    2、点击下一页时,能够保存条件,用同样的条件进行查询显示

                                                    3、日期在前台的显示

1、返回的对象类的DTO为

MatchMedicineDto.java

package com.yihaodian.pis.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.yihaodian.pis.util.DateFormatUtil;

public class MatchMedicineDto {
	/** 存储的ID */
	private Integer id ;
	/** 一号店商品编号 */
    private Integer productId;
    
    /** 一号店商品名 */
    private String productCname;
    
    /** 一号店商品编码 */
    private String productCode = null;

    /** 目标商品名 */
    private String name;
    
    /** 目标商品URL */
    private String pageUrl;
    
    /** 一号店分类id */
    private Integer categoryId = null;
    
    private String categoryName;
          
    private Integer siteId;
    /** 目标网站 名 */
    private String siteName;
	
    /** 匹配时间 */
    private Date matchTime;
    
    private String matchTimeStr;
    
    /**标志是1一号店还是2药网的信息 */
    private Integer ownSiteId = 1;
    
    private String condition;

    private Integer currentPage=1;
	private Integer iDisplayStart = 0;
	private Integer iDisplayLength = 20;
	private Integer pageCount;
	
	private List<Integer> catIdsIn;
	//将这个实体类里的几个属性变为一个字符串数组
//	public String[] toArray(int indexNum) {
//		String[] ret = new String[7];
//		
//		ret[0] = "<input type=\"checkbox\"  name=\"matchId\" οnclick=\"chooseMatch()\" value=\""+productId+"\"/>" ;
//		ret[1] = "<a href=\"http://www.111.com.cn/product/"+((productId/10)%10000000)*10000000+"\">"+productCname+"</a>" ;
//		ret[2] = ""+productCode;
//		ret[3] = ""+categoryName;
//		ret[4] = siteName;
//		ret[5] = "<a href=\""+pageUrl+"\" target=\"_blank\">"+name+"</a>";
//		ret[5] =  DateFormatUtil.getDate(matchTime, "yyyy-MM-dd");
//		
//		return ret;
//	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getProductId() {
		return productId;
	}

	public void setProductId(Integer productId) {
		this.productId = productId;
	}

	public String getProductCname() {
		return productCname;
	}

	public void setProductCname(String productCname) {
		this.productCname = productCname;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPageUrl() {
		return pageUrl;
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public Integer getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Integer categoryId) {
		this.categoryId = categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public Integer getSiteId() {
		return siteId;
	}

	public void setSiteId(Integer siteId) {
		this.siteId = siteId;
	}

	public String getSiteName() {
		return siteName;
	}

	public void setSiteName(String siteName) {
		this.siteName = siteName;
	}

	public Date getMatchTime() {
		return matchTime;
	}

	public void setMatchTime(Date matchTime) {
		this.matchTime = matchTime;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getiDisplayStart() {
		return iDisplayStart;
	}

	public void setiDisplayStart(Integer iDisplayStart) {
		this.iDisplayStart = iDisplayStart;
	}

	public Integer getiDisplayLength() {
		return iDisplayLength;
	}

	public void setiDisplayLength(Integer iDisplayLength) {
		this.iDisplayLength = iDisplayLength;
	}

	public Integer getPageCount() {
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public String getCondition() {
		return ownSiteId+","+productCode+","+siteId+","+categoryId;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public Integer getOwnSiteId() {
		return ownSiteId;
	}

	public void setOwnSiteId(Integer ownSiteId) {
		this.ownSiteId = ownSiteId;
	}

	public List<Integer> getCatIdsIn() {
		return catIdsIn;
	}

	public void setCatIdsIn(List<Integer> catIdsIn) {
		this.catIdsIn = catIdsIn;
	}

	public String getMatchTimeStr() {
		java.text.DateFormat   format=new   java.text.SimpleDateFormat( "yyyy-MM-dd hh:mm:ss");
		String   dateString=format.format(matchTime);
		return dateString;
	}

	public void setMatchTimeStr(String matchTimeStr) {
		this.matchTimeStr = matchTimeStr;
	}
	
}

 2、MedicineAction.java

在这里得到LIST,以及从数据库读取的起始位置和长度的设置

public class MedicineAction extends StrutsActionAdapter {

	/**
	 * author : 向旗
	 */
	private static final long serialVersionUID = 1L;
	/** 匹配商品列表 */
	private List<MatchMedicineDto> matchMedicineList;
	/** 列表 */
	private MatchProductService matchProductSvc;
	/** 药网目录提取 */
	private MedicineDao medicineDao;	
    /** 产品匹配记录id */
    private int matchId;
    /** 产品匹配记录id集合 */
    private String matchIds;
    
	private MatchProductDao matchProductDao;
	/** 第一级目录 */
	private List<MedicineCategoryDto> firstLevelCate;
	/** 父类的ID值 */
	private Integer parentCategoryId;
	/** 临时存商品编码的信息 */
	 /** 商品抓价业务接口 */
    private CurrentPriceService currentPriceSvc;
    /** 商品历史价格业务接口 */
    private HistoryPriceService historyPriceSvc;
    /** 异常错误信息 */
    private String message;

	private MatchMedicineDto matchMedicineDto = new MatchMedicineDto();
	/** 临时转存搜索条件信息*/
	private MatchMedicineDto mmDto = new MatchMedicineDto();

	private Integer pageNum = 1;
	
	private Integer next = 0 ; 
	
	private String condition;
public String queryMedicineByCode() {
		if (next == 1) {
			String[]conf = condition.split(",");
			mmDto.setOwnSiteId(Integer.parseInt(conf[0]));
			mmDto.setProductCode(conf[1]);
			mmDto.setSiteId(Integer.parseInt(conf[2]));
			if (conf[3].equals(null) || conf[3].equals("null")) {
				mmDto.setCategoryId(null);
			}else{
				mmDto.setCategoryId(Integer.parseInt(conf[3]));
				List<Integer> cl=new ArrayList<Integer>();
				if(medicineDao.getCategoryNameById(mmDto.getCategoryId()).getCategoryIsLeaf()==1)
				{
					cl.add(mmDto.getCategoryId());
				}else{
				List<CategoryDto> categoryList = medicineDao.getCategoryChilds(mmDto.getCategoryId());
				List<CategoryDto> fCategoryList =new ArrayList<CategoryDto>();
				for(int i = 0;i<categoryList.size();i++){
					if(categoryList.get(i).getCategoryIsLeaf()==1)
						fCategoryList.add(categoryList.get(i));
					else
						fCategoryList.addAll(medicineDao.getCategoryChilds(categoryList.get(i).getId()));
				}
				for(int i=0;i<fCategoryList.size();i++){
					cl.add(fCategoryList.get(i).getId());
				}
				}
				mmDto.setCatIdsIn(cl);
			}
			Integer count = matchProductDao.searchMeCountByCode(mmDto);
			mmDto.setPageCount((count+19)/20);
			if (pageNum==0) {
				pageNum = 1;
			}else if (pageNum > ((count+19)/20)) {
				pageNum = ((count+19)/20);
			}
			mmDto.setCurrentPage(pageNum);
			mmDto.setiDisplayStart((mmDto.getCurrentPage()-1)*20);
			matchMedicineList  =  matchProductDao.searchMeByCode(mmDto);
			matchMedicineDto = mmDto;
		}else {
			if (matchMedicineDto.getCategoryId() == 0) {
				matchMedicineDto.setCategoryId(null);
				matchMedicineDto.setCatIdsIn(null);
			}else{
				List<Integer> cl=new ArrayList<Integer>();
				if(medicineDao.getCategoryNameById(matchMedicineDto.getCategoryId()).getCategoryIsLeaf()==1)
				{
					cl.add(matchMedicineDto.getCategoryId());
				}else{
				List<CategoryDto> categoryList = medicineDao.getCategoryChilds(matchMedicineDto.getCategoryId());
				List<CategoryDto> fCategoryList =new ArrayList<CategoryDto>();
				for(int i = 0;i<categoryList.size();i++){
					if(categoryList.get(i).getCategoryIsLeaf()==1)
						fCategoryList.add(categoryList.get(i));
					else
						fCategoryList.addAll(medicineDao.getCategoryChilds(categoryList.get(i).getId()));
				}
				
				for(int i=0;i<fCategoryList.size();i++){
					cl.add(fCategoryList.get(i).getId());
				}
				}
				matchMedicineDto.setCatIdsIn(cl);
			}
			Integer count = matchProductDao.searchMeCountByCode(matchMedicineDto);
			matchMedicineDto.setPageCount((count+19)/20);
			matchMedicineDto.setCurrentPage(pageNum);
			matchMedicineDto.setiDisplayStart((matchMedicineDto.getCurrentPage()-1)*20);
			matchMedicineList  =  matchProductDao.searchMeByCode(matchMedicineDto);
		}
		//下位读取种类名称的代码
		for(int i =0;i<matchMedicineList.size();i++){
			CategoryDto cd = medicineDao.getCategoryNameById(matchMedicineList.get(i).getCategoryId());
			matchMedicineList.get(i).setCategoryName(cd.getCategoryName());
		}
		return "queryMedicineByCode";
	}
}

 3、页面的相关设置,以及跳转的参数传递

querymedicine.jsp

<table class="display" id="queryResultTbl">
	<thead>
		<tr id="headTitle">
		    <th  style="background-color: #5eaeae" ><input type="checkbox" id="chooseBox" onchange = "chooseAll()"/>&nbsp;&nbsp;&nbsp;&nbsp;全选</th>
			<th  style="background-color: #5eaeae" >药网商品链接</th>
			<th  style="background-color: #5eaeae" >商品编码</th>
			<th  style="background-color: #5eaeae" >药网分类</th>
			<th  style="background-color: #5eaeae" >目标网站</th>
			<th  style="background-color: #5eaeae" >目标商品链接</th>
			<th  style="background-color: #5eaeae" >商品匹配时间</th>
		</tr>
	</thead>
		<tbody id="tobyContent" style="text-align:center">
			<s:iterator value="matchMedicineList" id="matchMedicine" status="coll">
			<tr align="center">
				<td><input type="checkbox"  name="matchId" οnclick="chooseMatch()" value="${matchMedicine.id}"/></td>
				<td><a href="http://www.111.com.cn/product/${matchMedicine.productId}">${matchMedicine.name}</a></td>
				<td>${matchMedicine.productCode}</td>
				<td>${matchMedicine.categoryName}</td>
				<td>${matchMedicine.siteName}</td>
				<td><a href="${matchMedicine.pageUrl}" target="_blank">${name}</a></td>
				<td>${matchMedicine.matchTimeStr}</td>
			</tr>
			</s:iterator>
		</tbody>
		<tr><td><div>
<a href="medicineAction_queryMedicineByCode.action?next=1&pageNum=1&condition=${matchMedicineDto.condition}">首页</a>
<a href="medicineAction_queryMedicineByCode.action?next=1&pageNum=${matchMedicineDto.currentPage+1}&condition=${matchMedicineDto.condition}">下一页</a>
<a href="medicineAction_queryMedicineByCode.action?next=1&pageNum=${matchMedicineDto.currentPage-1}&condition=${matchMedicineDto.condition}">上一页</a>
<a href="medicineAction_queryMedicineByCode.action?next=1&pageNum=${matchMedicineDto.pageCount}&condition=${matchMedicineDto.condition}">尾页</a>
<span>总共${matchMedicineDto.pageCount}页</span>
 </div>
</td></tr>
	<tr><td><input type="button" value="删 除" class="button2" οnclick="delMatch()" id="delbutton"/></td></tr></table>

 不懂的问QQ526151410

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值