由register-1頁面跳轉到 controller.java中的addGuest方法,註冊成功返回到register-2頁面html
register-1.htmljava
<div class="container"> <a href="@{/}"><img src="images1/logo.jpg" alt=""/></a> <span th:if="${#fields.hasErrors('${guestForm.*}')}"><span th:errors="${guestForm.*}"></span></span>//消息驗證 <span th:text="${message}"></span> <span class="tit yh">新用戶註冊</span> </div>
<form action="addGuest" th:object="${guestForm}" method="post" class="form-horizontal">session
<div class="form-group">app
<span><label class="col-sm-4 control-label">用戶名:<span style="display:inline;color:red;">*</span></label></span> post
<div class="col-sm-8">編碼
<span><input name="guestId" type="text" th:value="${guestForm.guestId}" class="form-control"/></span>spa
</div>code
</div>orm
<div class="form-group">htm
<span><label class="col-sm-4 control-label">密碼:<span style="display:inline;color:red;">*</span></label></span>
<div class="col-sm-8">
<span><input name="password" type="password" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">重複密碼:</label></span>
<div class="col-sm-8">
<span><input name="passwordConfirm" type="password" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">姓名<span style="display:inline;color:red;">*</span></label></span>
<div class="col-sm-8">
<span><input name="guestName" type="text" th:value="${guestForm.guestName}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">性別</label></span>
<div class="col-sm-8">
<span><input name="gender" type="text" th:value="${guestForm.gender}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">收貨地址<span style="display:inline;color:red;">*</span></label></span>
<div class="col-sm-8">
<span><input name="address" type="text" th:value="${guestForm.address}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">移動電話號碼<span style="display:inline;color:red;">*</span></label></span>
<div class="col-sm-8">
<span><input name="mobile" type="text" th:value="${guestForm.mobile}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">Email</label></span>
<div class="col-sm-8">
<span><input name="email" type="text" th:value="${guestForm.email}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">QQ</label></span>
<div class="col-sm-8">
<span><input name="qq" type="text" th:value="${guestForm.qq}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">座機號碼</label></span>
<div class="col-sm-8">
<span><input name="phone" type="text" th:value="${guestForm.phone}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<span><label class="col-sm-4 control-label">郵政編碼</label></span>
<div class="col-sm-8">
<span><input name="zip" type="text" th:value="${guestForm.zip}" class="form-control"/></span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<span><input type="submit" value="提交" /></span>
</div>
</div>
</form>
controller.java
@RequestMapping(value = "addGuest", method = RequestMethod.POST) public String executeAddGuest(Model model,HttpSession session, @Valid @ModelAttribute("guestForm") GuestForm guestForm, BindingResult results, Device device) throws SQLException { model.addAttribute("guestForm", guestForm); GoodsForm goodsForm = new GoodsForm(); // goodsForm.setType("糧食"); // model.addAttribute("commodityType", goodsService.getType(goodsForm)); // model.addAttribute("goodsForm", goodsForm); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); if (results.hasErrors()) { log.info("內容驗證出錯"); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); if(device.isNormal()) { return "shop/register-1"; } else { return "mobile/register-1"; } } if(guestForm.getGuestId().length() > 4 && "Guest".equals(guestForm.getGuestId().substring(0, 5))) { log.info("ID驗證出錯"); model.addAttribute("message", "Guest是系統預留關鍵字,請避免使用!"); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); if(device.isNormal()) { return "shop/register-1"; } else { return "mobile/register-1"; } } if (!guestForm.getPassword().equals(guestForm.getPasswordConfirm())) { log.info("密碼驗證出錯"); model.addAttribute("message", "密碼和密碼確認必須一致!"); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); if(device.isNormal()) { return "shop/register-1"; } else { return "mobile/register-1"; } } log.info("添加客戶信息"); guestForm.setUpdateUser(guestForm.getGuestId()); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); guestForm.setUpdateTime(dateformat.format(date)); boolean result = guestService.addGuest(guestForm); if(!result) { //throw new SQLException("客戶信息添加失敗!"); model.addAttribute("message", "該用戶ID已被佔用,請更換用戶ID!"); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); if(device.isNormal()) { return "shop/register-1"; } else { return "mobile/register-1"; } } UVO uvo = new UVO(); uvo.setGuestId(guestForm.getGuestId()); uvo.setGuestName(guestForm.getGuestName()); uvo.setPassword(guestForm.getPassword()); uvo.setGender(guestForm.getGender()); uvo.setAddress(guestForm.getAddress()); uvo.setEmail(guestForm.getEmail()); uvo.setMobile(guestForm.getMobile()); uvo.setQq(guestForm.getQq()); uvo.setPhone(guestForm.getPhone()); uvo.setZip(guestForm.getZip()); session.setAttribute("UVO", uvo); // GoodsForm goodsForm = new GoodsForm(); // goodsForm.setType("糧食"); // model.addAttribute("commodityType", goodsService.getType(goodsForm)); // model.addAttribute("goodsForm", goodsForm); model.addAttribute("list", goodsService.searchGoodsList(goodsForm)); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/register-2"; } else { return "mobile/register-2"; } }
register-2.html
<div class="row regResult"> <div class="col-sm-6 tc"> <i class="ico-succ mt30"></i> <h4 class="regTips yh">恭喜您,註冊成功!</h4> <p><a class="btn btn-success ml10" th:href="@{/}">去首頁逛逛</a></p> </div> <div class="col-sm-6 r f14"> <p>已經是好農易會員?<a href="@{initGuestLogin}" class="link">去登陸</a></p> <img src="images1/qr.jpg" alt=""/> <p class="gray">掃描二維碼安裝好農易商城安卓客戶端</p> </div> </div>