I am creating my web application using microservices architecture. Here front-end application, Angular 2 will communicate with back end microservices developing using Spring MVC, Spring Boot and Spring Data JPA.
Here my sample controller action only like this,
@CrossOrigin(origins = "http://localhost:4200")
@RequestMapping(value = "/checkAuthentication", method = RequestMethod.POST)
public String checkLoginByName(@RequestBody Users user) throws Exception{
ObjectMapper mapper = new ObjectMapper();
Users useObj1 = userRepo.findByUsernameAndPassword(user.username,user.password);
return(mapper.writeValueAsString(useObj1));
}
Here I need to add status also.
Try returning a ResponseEntity:
@CrossOrigin(origins = "http://localhost:4200")
@RequestMapping(value = "/checkAuthentication", method = RequestMethod.POST)
public ResponseEntity checkLoginByName(@RequestBody Users user) throws Exception{
ObjectMapper mapper = new ObjectMapper();
Users useObj1 = userRepo.findByUsernameAndPassword(user.username,user.password);
return ResponseEntity<>(mapper.writeValueAsString(useObj1), HttpStatus.OK);
}