我正在使用微服务架构创建我的Web应用程序。这里的前端应用程序,angular 2将与使用spring MVC,spring boot和spring Data JPA开发的后端微服务进行通信。
这里我的样本控制器操作只有这样,
@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));
}
在这里我还需要添加状态。任何人都可以帮我澄清这个状态添加问题吗?
答案 0 :(得分:1)
尝试返回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);
}