Inserting a new user

Find the code snippet for addNewUser() operation:

//    Inserting new User
@PostMapping(path = ["/user/new"])
fun addNewUser(@RequestBody userModel: UserModel): String {
ResponseEntity(userService.addNewUser(userModel), HttpStatus.CREATED)
return "${userModel.name} has been added to database"
}

The @PostMapping(path = ["/user/new"]) annotation is the URL path of "/user/new", and it is a POST request. Here, we can insert user details into the database.

Here, @RequestBody is an annotation of the Spring MVC framework. This is used in a controller to implement object serialization and deserialization. It helps you to avoid boilerplate codes by extracting the logic. The @RequestBody annotated function returns a value that is bound to the HTTP web response body. Here, the object is UserModel

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.88.62