html1中index.html
<a th:href="@{initGuestLogin}" class="link" > <span th:if="${ #strings.isEmpty(session.UVO.guestName)}">登录</span></a>
GustController.java
@RequestMapping(value = "initGuestLogin", method = RequestMethod.GET)
public String initGuestLogin(Model model, Device device) {
log.info("客户登录界面初始化");
GoodsForm goodsForm = new GoodsForm();
goodsForm.setType("粮食");
model.addAttribute("goodsForm", goodsForm);
List<CartForm> cartList = new ArrayList<>();
model.addAttribute("cartList", cartList);
GuestForm guestForm = new GuestForm();
model.addAttribute("guestForm", guestForm);
if(device.isNormal()) {
return "shop/login";
} else {
return "mobile/login";
}
}
login.html
<div class="container mt20 regBox ">
<form action="guestLogin" class="form-horizontal" th:object="${guestForm}" method="post">
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label">用户名:</label>
<div class="col-sm-8">
<input type="text" name="guestId" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">密 码:</label>
<div class="col-sm-8">
<input type="password" name="password" class="form-control"/>
<i class="formInfo red">密码错误</i>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="checkbox w300 cf"><label class="fl"><input type="checkbox"/> 记住密码</label><a href="#" class="fr link">忘记密码?</a></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btnYellow yh">登 录</button>
</div>
</div>
</form>
GustController.java
@R equestMapping(value = "guestLogin", method = RequestMethod.POST)
public String guestLogin(Model model, HttpSession session, GuestForm guestForm, Device device) {
log.info("客户登录,验证客户信息,成功后进入系统");
GuestForm result = guestService.searchGuest(guestForm);
if(result != null) {
UVO uvo = new UVO();
uvo.setGuestId(result.getGuestId());
uvo.setGuestName(result.getGuestName());
uvo.setPassword(guestForm.getPassword());
uvo.setGender(result.getGender());
uvo.setAddress(result.getAddress());
uvo.setEmail(result.getEmail());
uvo.setMobile(result.getMobile());
uvo.setQq(result.getQq());
uvo.setPhone(result.getPhone());
uvo.setZip(result.getZip());
session.setAttribute("UVO", uvo);
GoodsForm goodsForm = new GoodsForm();
goodsForm.setType("粮食");
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/index";
} else {
return "mobile/index";
}
} else {
model.addAttribute("message", "用户名或密码错误!");
GoodsForm goodsForm = new GoodsForm();
goodsForm.setType("粮食");
model.addAttribute("goodsForm", goodsForm);
List<CartForm> cartList = new ArrayList<>();
model.addAttribute("cartList", cartList);
if(device.isNormal()) {
return "shop/login";
} else {
return "mobile/login";
}
}
}