开发者社区> 问答> 正文

Spring Boot URL被附加

我正在学习Java Web App开发。 我正在尝试通过@PutMapping请求更新用户的数据,但是我的URL值不正确。当我查看用户个人资料时,我的URL看起来像baseURL/userProfile/username。这里的username是主键(User类的ID)。当我单击更新配置文件按钮时,URL变为/userProfile/userProfile/username。它应该与上一个相同。这是我的Get和Put请求方法。

获取方法

@RequestMapping("/userProfile/{username}")
    public ModelAndView viewProfile(ModelAndView mv, @ModelAttribute("user") User user, 
            @PathVariable("username") String username) {

        user = userService.getUserDetailByEmailOrUsername(username, "UserProfile");

        System.out.println("Inside /profile\nUsername = " + user.getUsername());
        mv.setViewName("profile");

        mv.addObject("user", user);

        return mv;
    }

放置方法:

@PutMapping("userProfile/{username}")
    public ModelAndView updateProfile(ModelAndView mv, User user, 
            @PathVariable("username") String username) {

        System.out.println("Inside /updateProfile\nUsername = " + user.getUsername());
        userService.updateUser(user);
        mv.setViewName("dashboard");
        mv.addObject("msg", "Profile Updated Successfully!");

        return mv;
    }

这是JSP中的配置文件表单

<form:form modelAttribute="user" class="signup-form bg-dark text-light d-flex flex-column align-items-center" action="userProfile/${username}" method="Post"
      oninput="result.value=!!confirm_password.value&&(uPassword.value==confirm_password.value)?'Matched!':'Both password fields must be same!'">
      <div class="text-center mb-4">
            <img class="mb-4" src="images/img_avatar2.png" alt="" width="72" height="72">
            <h2 class="form-signin-heading"></h2>
            <p>Here is your Profile Information</p>
            <hr>
            </div>
            <div class="input-group">
                 <div class="input-group-prepend">
                     <span class="input-group-text">
                         <span class="fa fa-user"></span>
                     </span>                    
                 </div>
                 <form:input type="text" class="form-control" name="username" path="username" disabled="true" placeholder="Username" autofocus=""/>
             </div>
             <br>
             <div class="input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text">
                         <span class="fa fa-envelope"></span>
                    </span>                    
                </div>
                <form:input type="email" class="form-control" name="email" path="email" placeholder="Email Address"/>
             </div>
             <br>
             <div class="input-group">
                 <div class="input-group-prepend">
                      <span class="input-group-text">
                           <span class="fa fas fa-address-card"></span>
                      </span>                    
                  </div>
                  <form:input class="form-control" name="fullName" path="fullName" placeholder="Full Name(name & surname)"/>
              </div>
              <br>
              <br>
              <br>
              <div class="input-group">
                  <div class="input-group-prepend">
                      <span class="input-group-text">
                           <span class="fa fa-lock"></span>
                      </span>                    
                  </div>
                  <input type="password" class="form-control" name="oldPassword" placeholder="Old Password Here">
             </div>
             <br>
             <div class="input-group">
                 <div class="input-group-prepend">
                     <span class="input-group-text">
                         <span class="fa fa-lock"></span>
                     </span>                    
                 </div>
                 <input type="password" class="form-control" name="newPassword" placeholder="New Password Here">
             </div>
             <br>
             <div class="input-group">
                  <div class="input-group-prepend">
                      <span class="input-group-text">
                           <span class="fa fa-lock"></span>
                           <span class="fa fa-check"></span>
                           </span>                    
                  </div>
                  <input type="password" class="form-control" name="confirm_password" placeholder="Confirm New Password">
           </div>
           <output name="result" style="text-decoration: blink; color: red"></output>
           <br>

           <br>
           <div class="form-group">
           <button type="submit" class="btn btn-primary btn-lg">Update Profile</button>
    </div>
</form:form>

请指出为什么我userProfile两次获得该URL。我认为上述代码足以找出问题所在。如果需要公开更多代码/类,请告诉我。

问候Inzimam Tariq

展开
收起
垚tutu 2019-12-19 15:58:34 436 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多