注册 功能的实现

由register-1页面跳转到 controller.java中的addGuest方法,注册成功返回到register-2页面

register-1.html

?
1
2
3
4
5
6
<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">

   <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="guestId" type="text" th:value="${guestForm.guestId}" 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="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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  
     @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

?
1
2
3
4
5
6
7
8
9
10
11
12
<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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值