ปัญหาขณะโพสต์ข้อมูลโดยใช้ spring และ AngularJS :: คำขอที่ส่งโดยไคลเอ็นต์ไม่ถูกต้องทางไวยากรณ์

ฉันได้รับข้อผิดพลาดด้านล่างขณะโพสต์ไปยังบริการที่เหลือ โปรดช่วยฉันเข้าใจว่าฉันพลาดอะไรไปที่นี่

The request sent by the client was syntactically incorrect.

รหัสคอนโทรลเลอร์ของฉันคือ:

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody String addUser(@RequestBody UserDomain userDomain, BindingResult result) {
    System.out.println("UserDomain :: " + userDomain);
    userService.addUser(userDomain);
    return "redirect:/";
}

บริการ js

services.factory('UserFactory', ['$resource', function ($resource) {

return  {
    usercreation: $resource('/ngdemo/web/users', {}, {
        query: {method: 'GET', isArray: true },
        create: {method: 'POST'}
    })

}; }]);

คอนโทรลเลอร์.js

    app.controller('DemoCtrl', ['$scope', 'UserFactory', '$facebook', 'NotificationFactory', '$location', function ($scope, UserFactory, $facebook, NotificationFactory, $location) {

        $scope.UserDomain = { firstname: null };

        $scope.isLoggedIn = false;
        $scope.login = function () {
            $facebook.login().then(function () {
                refresh();
            });
        }

        function refresh() {
            $facebook.api("/me").then(
                function (response, Userfactory) {
                    $scope.welcomeMsg = "Welcome " + response.name;
                    $scope.result = response;
                    console.log("console ctrl demo12 - " + $scope.welcomeMsg);
                    alert($scope.result);
                    $scope.isLoggedIn = true;

                    //$scope.UserDomain.id = $scope.result.id;
                    $scope.UserDomain.socialId = $scope.result.id;
                    $scope.UserDomain.gender = $scope.result.gender;
                    $scope.UserDomain.firstname = $scope.result.first_name;
                    $scope.UserDomain.hometown = $scope.result.hometown.name;
                    $scope.UserDomain.currentLocation = $scope.result.location.name;
                    $scope.UserDomain.lastname = $scope.result.last_name;
                    $scope.UserDomain.email = $scope.result.email;
                    $scope.UserDomain.username = $scope.result.username;
                    $scope.UserDomain.link = $scope.result.link;
                    $scope.UserDomain.relationshipStatus = $scope.result.relationship_status;

                    console.log("$scope.result - " + $scope.result.relationship_status);
                    console.log("$scope.UserDomain - " + $scope.UserDomain.relationshipStatus);

                    //making call to add user
                    UserFactory.usercreation.create($scope.UserDomain);
                },
                function (err) {
                    $scope.welcomeMsg = "Please log in";
                });
        }
    }]);

JSON สร้างและตรวจสอบในคอนโซล Mozilla ::

{"firstname":"Naveuuuin","socialId":"7048797897728972","gender":"male","hometown":"Udaipur, Rajasthan","currentLocation":"Bangalore, India","lastname":"Vyas","email":"[email protected]","username":"vyas","link":"https://www.facebook.com/vyas","relationshipStatus":"Single"}

คลาส UserDomain คือ:

    package ngdemo.domain;

    import javax.persistence.*;

    @Entity
    @Table(name = "P_USER")
    public class UserDomain {

        @Id
        @Column(name = "USER_ID")
        @GeneratedValue
        private Integer id;

        @Column(name = "SOCIAL_ID")
        private String socialId;

        @Column(name = "FIRSTNAME")
        private String firstname;

        @Column(name = "LASTNAME")
        private String lastname;

        @Column(name = "EMAIL")
        private String email;

       /* @Column(name = "PHONENUMBER")
        private String telephone;*/

        @Column(name = "HOMETOWN")
        private String homeTown;

        @Column(name = "GENDER")
        private String gender;

        @Column(name = "LINK")
        private String link;

        @Column(name = "CURRENT_LOCATION")
        private String currentLocation;

        @Column(name = "RELATIONSHIP_STATUS")
        private String relationshipStatus;

        @Column(name = "USERNAME")
        private String username;

        public String getSocialId() {
            return socialId;
        }

        public void setSocialId(String socialId) {
            this.socialId = socialId;
        }

        public String getCurrentLocation() {
            return currentLocation;
        }

        public void setCurrentLocation(String currentLocation) {
            this.currentLocation = currentLocation;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }

        public String getHomeTown() {
            return homeTown;
        }

        public void setHomeTown(String homeTown) {
            this.homeTown = homeTown;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }

        public String getRelationshipStatus() {
            return relationshipStatus;
        }

        public void setRelationshipStatus(String relationshipStatus) {
            this.relationshipStatus = relationshipStatus;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getEmail() {
            return email;
        }

       /* public String getTelephone() {
            return telephone;
        }*/

        public void setEmail(String email) {
            this.email = email;
        }

       /* public void setTelephone(String telephone) {
            this.telephone = telephone;
        }*/

        public String getFirstname() {
            return firstname;
        }

        public String getLastname() {
            return lastname;
        }

        public void setFirstname(String firstname) {
            this.firstname = firstname;
        }

        public void setLastname(String lastname) {
            this.lastname = lastname;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        @Override
        public String toString() {
            return "UserDomain{" +
                    "currentLocation='" + currentLocation + '\'' +
                    ", id=" + id +
                    ", socialId=" + socialId +
                    ", firstname='" + firstname + '\'' +
                    ", lastname='" + lastname + '\'' +
                    ", email='" + email + '\'' +
                    ", homeTown='" + homeTown + '\'' +
                    ", gender='" + gender + '\'' +
                    ", link='" + link + '\'' +
                    ", relationshipStatus='" + relationshipStatus + '\'' +
                    ", username='" + username + '\'' +
                    '}';
        }
    }

person AngryJS    schedule 08.04.2014    source แหล่งที่มา


คำตอบ (1)


ขอบคุณทุกคนอยู่แล้ว!

ทุกอย่างถูกต้อง ปัญหาเดียวคือกรณีใน JSON ที่ส่งคืนและโมเดลโดเมนของฉัน

person AngryJS    schedule 08.04.2014