配置文件中:有關客戶端是手機仍是電腦的判斷(GoodsController.java)html
public String initGoods(Model model, HttpSession session, GoodsForm goodsForm, Device device) throws UnsupportedEncodingException
2.網站的錯誤頁面(error.jsp),會返回錯誤信息,並提示這是一個錯誤頁面java
<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),例如,網站圖片的加載,初次加載時會訪問數據庫,再次請求則會先去緩存中找,若沒有再去數據庫中查找web
<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.首頁模糊查詢sql
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中 canvas
@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>
5.將<jsp:include page="/WEB-INF/jsp/shop/userBar.jsp"></jsp:include>改成服務器
<div th:replace="shop/userBar :: page-user-bar"></div>session
6. 靜態方法(static)能夠直接調用,只存在於一個固定空間區域,通常算術時使用;app
而非靜態方法須要建立對象,每次都調用不一樣的區域,可再次使用,互不影響,