如何从Android发送数据与Spring mvc中的模型对象绑定

时间:2016-01-06 06:38:17

标签: android spring-mvc

这是register.jsp文件部分没问题。如何从Android移动应用程序发送数据或我可以在控制器中进行任何更改,请协助。谢谢你的帮助。

@RequestMapping(value = "/register", method = RequestMethod.POST)
    public String createNewUser(Model model, @ModelAttribute(value = "user") User user,
      BindingResult errors, HttpServletRequest request) {
      // this is working properly for both mobile and laptop(directly website) links
      user.getUsername()
        // here i am getting "NullPointerException" because email is binded to user and not to model not to UserMetaData Model in case of android, it is working fine laptop as in html file we are providing path="userMetaData.email"
        //So what to do send it in same way from android application too.
      user.getUserMetadata().getEmail();

      return "true";
    }
  

以下是我的Pojo课程

User.java

Public class User {
      private String username;

      @
      Column(name = "USERNAME", unique = true, nullable = false, length = 80)
      public String getUsername() {
        return this.userName;
      }

      public void setUsername(String userName) {
        this.userName = userName;
      }
    }

UserMetadata.java

public class UserMetadata {
      private String email;

      @
      Column(name = "EMAIL", unique = true, nullable = false, length = 40)
      public String getEmail() {
        return this.email;
      }
    }
  

以下是我的JSP页面: -

<label>Username</label>
    <form:input path="username" class="form-control input-sm bounceIn animation-delay2" placeholder="User Name" />
    </div>
    <!-- /form-group -->
    <div class="form-group">
      <label>Password</label>
      <form:password path="password" placeholder="Password" class="form-control input-sm bounceIn animation-delay3" />
    </div>
    <!-- /form-group -->
    <div class="form-group">
      <label>Confirm Password</label>
      <input type="password" placeholder="Confirm password" id='confirmpass' name='confirmpass' class="form-control input-sm bounceIn animation-delay4">
    </div>
    <!-- /form-group -->
    <div class="form-group">
      <label>Email Address</label>
      <form:input path="userMetadata.email" id='email' placeholder="Email address" class="form-control input-sm bounceIn animation-delay5" />
    </div>
    <!-- /form-group -->

请以示例的方式给你答案,实际上数据是保存在数据库中所以我无法更改模型,我必须以这样的方式绑定数据,即我应该以与它相同的方式使用模型我只能在弹簧的android代码或控制器代码中进行更改。

0 个答案:

没有答案