- 配置文件中:有关客户端是手机还是电脑的判断(GoodsController.java)
public String initGoods(Model model, HttpSession session, GoodsForm goodsForm, Device device) throws UnsupportedEncodingException
2.网站的错误页面(error.jsp),会返回错误信息,并提示这是一个错误页面
-
<div class="row"> <div class="well col-md-5 center login-box"> <div class="alert alert-info"> ${exceptionMessage} </div> <form class="form-horizontal" action="${pageContext.request.contextPath}/" method="get"> <fieldset> <p> 这是一个错误页面说明服务器出现了问题,请返回首页重新登录。 </p> <p class="center col-md-5"> <button type="submit" class="btn btn-primary">返回首页</button> </p> </fieldset> </form> </div> <!--/span--> </div
3.缓存管理(ehcache),例如,网站图片的加载,初次加载时会访问数据库,再次请求则会先去缓存中找,若没有再去数据库中查找
<li><a href="#"><canvas></canvas> <img src="shop/images/banner1.jpg" /></a></li> <div class="grid_1_of_3 grid_1_of_3first images_1_of_3" th:class="${status.count%3==1}?‘grid_1_of_3 grid_1_of_3first images_1_of_3‘:‘grid_1_of_3 images_1_of_3‘" th:each="goodsInfo,status:${list}"> <img alt="商品详细情况" th:src="@{showImage(pictureId=${goodsInfo.pictureId})}" style="height:185px;width:330px;" />
@RequestMapping(value = "showImage", method = RequestMethod.GET) public void showImage(HttpServletResponse response, CommodityForm commodityForm) throws IOException { log.info("取得商品图片"); response.setContentType("image/jpg"); OutputStream stream = response.getOutputStream(); try { stream.write(commodityService.getPicture(commodityForm)); stream.flush(); } catch (Exception e) { log.info(commodityForm.getPictureId() + ",该图片不存在,需要补充!"); } finally { stream.close(); } }
4.首页模糊查询
- userBar.html中添加一个form表单
-
<form action="jiansuo" th:object="${guestForm}" method="post"> <li> </li> <li><span><input name="commodityName" type="text" /></span></li> <li> </li> <li><span><input name="jiansuo" type="submit" value="搜索" /></span></li> </form>
- controller与service中
-
@RequestMapping(value = "jiansuo", method = RequestMethod.POST,params="jiansuo") public String jiansuoGoods(Model model, HttpSession session, GoodsForm goodsForm, Device device) throws UnsupportedEncodingException { log.info("商品列表初始化"); model.addAttribute("goodsForm", goodsForm); model.addAttribute("list", goodsService.jiansuoGoodsList(goodsForm)); return "shop/index"; }
public List<GoodsForm> jiansuoGoodsList(GoodsForm frm) { List<GoodsForm> result = queryDao.executeForObjectList("Goods.jiansuoGoodsList", frm); return result; }
- sqlMap中的select
-
<select id="jiansuoGoodsList" parameterClass="cn.agriculture.web.form.GoodsForm" resultClass="cn.agriculture.web.form.GoodsForm"> SELECT commodity.commodity_id as commodityId, commodity.type as type, supplier.supplier_name as supplierName, brand.brand_name as brandName, commodity.commodity_name as commodityName, commodity.weight as weight, commodity.is_gift as isGift, commodity.specifications as specifications, commodity.unit as unit, commodity.benchmark_price as benchmarkPrice, commodity.guide_price as guidePrice, commodity.retail_price as retailPrice, commodity.competition_level as competitionLevel, commodity.note as note, commodity.update_time as updateTime, commodity.update_user as updateUser, commodity.picture_id as pictureId, stock.stock as stock FROM commodity, supplier, brand, stock WHERE commodityName like ‘%$commodityName$%‘ <!-- commodity.commodity_name like concat(‘%‘,#commodityName#,‘%‘) --> </select>
时间: 2024-10-11 20:04:27