Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created February 20, 2018 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visparashar/11fd9bc1d0743d76ef338ecf9dac1f53 to your computer and use it in GitHub Desktop.
Save visparashar/11fd9bc1d0743d76ef338ecf9dac1f53 to your computer and use it in GitHub Desktop.
package com.programinjava.learning.RestApiDemo.controller;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.programinjava.learning.RestApiDemo.dto.JsonUser;
import com.programinjava.learning.RestApiDemo.service.UserService;
@RestController
@RequestMapping("/api/user")
public class UserController {
@Autowired
UserService userService;
@PostMapping
public ResponseEntity<JsonUser> create(@RequestBody @Valid JsonUser user ,BindingResult result ,HttpServletRequest request){
if(user== null)
return ResponseEntity.badRequest().build();
return ResponseEntity.ok().body(userService.createUser(user));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment