angularjs - DTO for Spring and AnjularJS -
i wand process request angularjs. have dto-class:
public class logindto { private string login; private roleenum role; //setters , getters }
controller on backend:
@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"); homecoming logindto; } }
and controller on frontend:
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"); }); });
and @ frontend see failed
. if alter controller on backend:
@controller @requestmapping("/employeeservice/user") public class usercontroller { @requestmapping(method = requestmethod.get, value = "/userinfo") @responsebody public string currentuserinfo(){ homecoming "test"; } }
i see ok
. how utilize dto class?
on brawser error the server responded status of 406 (not acceptable)
,
the resource identified request capable of generating responses characteristics not acceptable according request "accept" headers.
let's add:
app.controller("test", function($scope, $http){ var response = $http({ method: "get", url: "/employeeservice/user/userinfo", <!--add--!> datatype: 'json', contenttype: 'application/json', mimetype: 'application/json' <!--end--!> }); response.success(function (data) { alert("ok"); }); response.error(function(data){ alert("failed"); }); });
angularjs spring controller dto
No comments:
Post a Comment