简体   繁体   中英

Design a restful url to validate the object

Is it possible to populate java object in spring MVC from restful URL.

To clarify, can I make a url like localhost:8080/user/email/a@a.com/password/aaa which will populate email and password field of User object and return me user?

@RequestMapping(value = "user/email/{email}/password/{password}", method = RequestMethod.POST)
    public ResponseEntity<Users> createNewUserRegistration(@Valid User user) {

}
public ResponseEntity<Users> createNewUserRegistration(@PathVariable("email")String email,@PathVariable("password")String password) {
User user = new User(email,password);
//do validation etc
return user;
}

Ok, finally it worked for me. You need to add it in your pom.xml

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.12</version>
</dependency>

@RequestMapping(value = "user", method = RequestMethod.POST)
    public ResponseEntity<Users> createNewUserRegistration(@RequestBody @Valid User user) {

}

and pass the json in the request body

{
    "emailAddress":"email",
    "password":"password"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM