Front-end merchandise display little knowledge of point 1

Abnormal, lazy loading. In ** **

* A set of two circular loop. Cascading lists. (Note <s: iterator var = "cs" value = "# c.categorySeconds"> categorySeconds in cascade set in Category.java).

		<s:iterator  value="categoryList" var="c" >
					<dl>
						<dt>
							<a href="${pageContext.request.contextPath}/image/蔬菜 - Powered By Mango Team.htm"><s:property value="#c.cname" /></a>
						</dt>
						<s:iterator var="cs" value="#c.categorySeconds" >
								<dd>
									<a ><s:property  value="#cs.csname" /></a>
								</dd>
						</s:iterator>		
					</dl>
					
					</s:iterator>

The total number of a particular classification of statistics.

public Integer findtotalCount(Integer cid) {

		List<Long> totalCount = this.getHibernateTemplate().find(

				"select count(*) from Product p ,CategorySecond cs where p.catagorys = cs and cs.category.cid = ? ",

				cid);
//catagorys是Product   Bean的中属性。
		System.out.println(totalCount.get(0).intValue());

		return totalCount.get(0).intValue();
}
/*
查询一级关联下的所有的商品。主要记SQl语句 还有个分页在

*/
public List<Product> findByPage(Integer cid, int begin, int limit) {
		String sql = "select p from Product p , CategorySecond cs where p.catagorys = cs and cs.category.cid = ? ";
		List<Product > list = this.getHibernateTemplate().executeFind(new PageHibernateCallback<Product>(sql, new Object[] { cid }, begin, limit));
		return list;
	}

Display paging. There PageBean as return the object to achieve in the foreground.

//PageBean bean
public class PageBean<T> {

private Integer page;//当前的页数

private Integer limit;//每页显示记录数

private Integer totalCount;//总记录数

private Integer totalPage;//总页数

private List<T> list;
get方法和set方法。。。。。。。。。。
}

public String findByCid() {
		//查询分类
		List<Category> categoryList = categoryService.findAll();
		ActionContext.getContext().getValueStack().set("categoryList", categoryList);
		//查询商品
    //把返回的数据放入PageBean中为了保存分页中的数据。
		PageBean<Product> pageBean = productService.findByCid(cid,page);
		//获得值栈
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findByCidSuccess";
	}

//下面就是分页步骤。
public PageBean<Product> findByCid(Integer cid, Integer page) {
		PageBean<Product> pageBean = new PageBean<Product>();
		int limit = 12;
		int totalPage = 0;
		pageBean.setPage(page);
		pageBean.setLimit(limit);
		//总记录数
		Integer totalCount = productDao.findtotalCount(cid);
		pageBean.setTotalCount(totalCount);
		if(totalCount % limit == 0) {
			totalPage = totalCount % limit;
		}else {
			totalPage = totalCount % limit + 1;
		}
		pageBean.setTotalPage(totalPage);
		//商品集合了
		int begin = (page-1) * limit ;
		List<Product> list =  productDao.findByPage(cid,begin,limit);
		pageBean.setList(list);
		return pageBean;
	}

// 统计某个分类下的商品的总数 主要记 hql语句
	public Integer findtotalCount(Integer cid) {
		List<Long> totalCount = this.getHibernateTemplate().find(
				"select count(*) from Product p ,CategorySecond cs where p.catagorys = cs and cs.category.cid = ? ",
				cid);

		return totalCount.get(0).intValue();

	}

	// 一级关联下的二级分类
	public List<Product> findByPage(Integer cid, int begin, int limit) {
		String sql = "select p from Product p , CategorySecond cs where p.catagorys = cs and cs.category.cid = ? ";
		List<Product> list = this.getHibernateTemplate()
				.executeFind(new PageHibernateCallback<Product>(sql, new Object[] { cid }, begin, limit));
		return list;
	}

Guess you like

Origin blog.csdn.net/qq_41922566/article/details/94647915