Pass Json data from angular JS to spring REST API and handling it

Praveen

I'm learning AngularJS and Spring MVC. I'm stuck in a situation where I have an angularjs controller from which I do a REST API call to a spring service. I would like to know how to accept those JSON values inside the controller and map to the Model (getters and setters).

I'm doing some validations on the spring side before doing an insert in the database. I would also like to know how to return those error messages to angula JS and populate them on the screen.

This is my AngularJS controller:

var myapp = angular.module("app");
myapp.controller("RedisplayController",function($scope,$localStorage,$http, $location,$window,) {
    $scope.addconfig = function() {    
        var dataobj = {
            escfirstname : $scope.escfirstname ,esclastname:$scope.esclastname,escage:$scope.escage 
        }
        $http({
            url: "http://localhost:8080/services/AddConfig", 
            method: "POST",
            data: dataobj,
            headers: { 
                'Accept': 'application/json',
                'Content-Type': 'application/json' 
            }
        });
    }
}); 

This is my Spring service:

@Controller
public class TestController {
    @RequestMapping(value = "/AddConfig",   method = RequestMethod.POST)
    public @ResponseBody String PostService(@RequestBody Config person) {
        System.out.println("came insidee");
        return null;
    }
}

I'm able to print the sysout. Now I would like to know how to proceed with this.

0gam

enter link description here

like this.

var myapp = angular.module("app");

myapp.controller("RedisplayController",function($scope,$localStorage,$http, $location,$window,) {
        $scope.addconfig = function() {    
   var dataObject = {
      escfirstname : $scope.escfirstname, 
      esclastname : $scope.esclastname, 
      escage : $scope.escage
   };

   $http({
      method: 'POST', 
      url: 'http://localhost/jsonURL',
      data: dataObject,
      headers: {'Content-Type': 'application/json; charset=utf-8'} 

   }).success(function(data, status, headers, config) {
      if( data ) {

      }
      else {

      }
   }).error(function(data, status, headers, config) {
      console.log(status);
   });
}
}); 

@Controller
public class TestController {

    @RequestMapping(value = "/AddConfig", method = RequestMethod.POST)
    public @ResponseBody String PostService(@RequestBody Config person) {

        // System.out.println("person" + person.);
        return null;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

POST data from Angular.js to Django REST API using JSON

From Dev

How to get data from rest api and show in angular js

From Dev

How to pass json data from C# controller to angular js?

From Dev

Handling data response from $resource in angular js

From Dev

Getting Json Data From API using Angular Js

From Dev

How to pass @EmbeddedId in POST json in spring-boot data rest

From Dev

Return JSOn data from a REST API in ColdFusion

From Dev

Send image with difference data type from angular 7 to Rest API in spring boot 2.0.5

From Dev

Angular handling return data from Web Api as error

From Dev

Angular JS $http.get returns empty data from WP REST API, but only on actual iOS device

From Dev

how to pass an array from angular js to REST service using $resource

From Dev

Custom exception handling for Spring Boot REST API

From Dev

Handling exceptions in Spring MVC along with Rest API

From Dev

Customizing Spring Data Rest @ManyToMany relationship handling

From Dev

Get JSON data from API with Angular 2

From Dev

How to pass json data through ajax in Angular Js

From Dev

Spring REST: Get JSON data from Request body in addition to entity

From Dev

Prevent spring-data-rest from parsing json

From Dev

How to pass data from factory to controller in angular js?

From Dev

How to pass data from one page to other page in angular js

From Dev

How to pass data from one page to other page in angular js

From Dev

how to pass data from service to directive in angular.js

From Dev

JSON REST API with Spring Security

From Dev

Session Handling in Angular JS, with Spring MVC

From Dev

Populate JSON data from REST API to table view in swift not working

From Dev

Firebase REST API get all data from node as JSON Array

From Dev

fetching rating data from database to JSON array in php rest api

From Dev

Receive JSON data from a webservice using REST API

From Dev

Fetching from REST API and storing json response for further filtering of data

Related Related

  1. 1

    POST data from Angular.js to Django REST API using JSON

  2. 2

    How to get data from rest api and show in angular js

  3. 3

    How to pass json data from C# controller to angular js?

  4. 4

    Handling data response from $resource in angular js

  5. 5

    Getting Json Data From API using Angular Js

  6. 6

    How to pass @EmbeddedId in POST json in spring-boot data rest

  7. 7

    Return JSOn data from a REST API in ColdFusion

  8. 8

    Send image with difference data type from angular 7 to Rest API in spring boot 2.0.5

  9. 9

    Angular handling return data from Web Api as error

  10. 10

    Angular JS $http.get returns empty data from WP REST API, but only on actual iOS device

  11. 11

    how to pass an array from angular js to REST service using $resource

  12. 12

    Custom exception handling for Spring Boot REST API

  13. 13

    Handling exceptions in Spring MVC along with Rest API

  14. 14

    Customizing Spring Data Rest @ManyToMany relationship handling

  15. 15

    Get JSON data from API with Angular 2

  16. 16

    How to pass json data through ajax in Angular Js

  17. 17

    Spring REST: Get JSON data from Request body in addition to entity

  18. 18

    Prevent spring-data-rest from parsing json

  19. 19

    How to pass data from factory to controller in angular js?

  20. 20

    How to pass data from one page to other page in angular js

  21. 21

    How to pass data from one page to other page in angular js

  22. 22

    how to pass data from service to directive in angular.js

  23. 23

    JSON REST API with Spring Security

  24. 24

    Session Handling in Angular JS, with Spring MVC

  25. 25

    Populate JSON data from REST API to table view in swift not working

  26. 26

    Firebase REST API get all data from node as JSON Array

  27. 27

    fetching rating data from database to JSON array in php rest api

  28. 28

    Receive JSON data from a webservice using REST API

  29. 29

    Fetching from REST API and storing json response for further filtering of data

HotTag

Archive