Map<Object, Object> root = new HashMap<Object, Object>();
root.putAll(super.root);
Template temp = getConfiguration().getTemplate("product/ProductList.ftl");
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
String pageno = request.getParameter("pageno");
//处理当前页
if(pageno==null) {
pageno = "1";
}
int pagenum = 1;
try {
pagenum = Integer.parseInt(pageno);
} catch (Exception e1) {
pagenum = 1;
}
root.put("Update_Product_Url", Constants.UPDATE_PRODUCT_URL);
String byProductId = request.getParameter("byProductId");
//根据商品编号精确查询
if("1".equals(byProductId)) {
/*String productid = request.getParameter("productid");
Product product = null;
try {
product = gatewayService.findProductById(Long
.parseLong(productid));
} catch (Exception e) {
product = null;
}
if(product!=null) {
List<Product> dataList = new ArrayList<Product>();
dataList.add(product);
PageList page = new PageList();
page.setCurrentPageNum(1);
page.setPageSize(Constants.PRODUCT_LIST_SIZE);
page.setTotalPageNum(1);
page.setTotalRecordNum(1);
page.setDataList(dataList);
root.put("page", page);
} else {
}*/
String code = request.getParameter("productid");
PageList page = gatewayService.findProductPageByCode(code, pagenum, Constants.PRODUCT_LIST_SIZE);
if(page!=null&&page.getDataList().size()>0) {
root.put("page", page);
}
} else {
String keyword = request.getParameter("keyword");
//处理关键字
String[] keys = null;
if(keyword!=null) {
keyword = keyword.trim();
}
if(keyword==null||"".equals(keyword)) {
keys = null;
} else {
root.put("keyword", keyword);
if(keyword.indexOf(" ")>0) {
String[] keywords = keyword.split(" ");
keys = new String[keywords.length+1];
keys[0] = keyword;
for(int i=1;i<keys.length;i++) {
keys[i] = keywords[i-1];
}
} else {
keys = new String[]{keyword };
}
}
String areaCategoryId = request.getParameter("areaCategoryId");
root.put("areaCategoryId", areaCategoryId);
String categoryId = request.getParameter("categoryId");
root.put("categoryId", categoryId);
long aid = -1;
long cid = -1;
try {
aid = Long.parseLong(areaCategoryId);
} catch (Exception e) {
aid = -1;
}
try {
cid = Long.parseLong(categoryId);
} catch (Exception e) {
cid = -1;
}
String keytype = request.getParameter("keytype");
root.put("keytype", keytype);
if(keytype==null) {
keytype = "1";
}
PageList page = gatewayService.findProductPage(aid, cid, keytype, keys, pagenum, Constants.PRODUCT_LIST_SIZE);
if(page!=null&&page.getDataList().size()>0) {
root.put("page", page);
}
}
/* 将模板和数据模型合并 */