0
AngularJS의 요청을 처리 할 수 있습니다. 백엔드에봄 및 영어에 대한 DTO
public class LoginDTO {
private String login;
private RoleEnum role;
//setters and getters
}
컨트롤러 :
@Controller
@RequestMapping("/EmployeeService/user")
public class UserController {
@RequestMapping(method = RequestMethod.GET, value = "/userInfo")
@ResponseBody
public LoginDTO currentUserInfo(){
LoginDTO loginDTO = new LoginDTO(RoleEnum.ROLE_ADMIN, "test");
return loginDTO;
}
}
그리고 컨트롤러 프론트 엔드에 : 그래서 DTO 클래스가
app.controller("test", function($scope, $http){
var response = $http({
method: "get",
url: "/EmployeeService/user/userInfo"
});
response.success(function (data) {
alert("ok");
});
response.error(function(data){
alert("failed");
});
});
을 그리고 프론트 엔드에서 나는 failed
를 참조하십시오. 백엔드 컨트롤러를 변경하면 :
@Controller
@RequestMapping("/EmployeeService/user")
public class UserController {
@RequestMapping(method = RequestMethod.GET, value = "/userInfo")
@ResponseBody
public String currentUserInfo(){
return "test";
}
}
나는 OK
을 참조하십시오. DTO 클래스를 사용하는 방법? brawser 오류에
the server responded with a status of 406 (Not Acceptable)
및
The resource identified by this request is only capable of generating responses with
characteristics not acceptable according to the request "accept" headers.
은'Accept' 요청 헤더의 값이 무엇입니까? 그것은'application/json'과 같아야합니다. 그렇다면 주석을 다음과 같이 변경하십시오 :'@RequestMapping (method = RequestMethod.GET, value = "/ userInfo", produce = "application/json")' –