How to integrate Http Angularjs with Spring MVC | Spring Boot

$http is an AngularJS service for communication with remote servers. In the article, JavaSampleApproach will show you way to integrate Http AngularJs and Spring Boot.

Related Articles:
How to configure AngularJs – SpringBoot
How to integrate Angular 4 with SpringBoot Web App and SpringToolSuite
MultipartFile – How to create Spring AngularJs MultipartFile application to download/upload files | SpringBoot + AngularJs + Bootstrap.
AngularJs POST-GET Nested Objects to SpringBoot server
AngularJs POST-GET LIST Objects to SpringBoot server


I. Technologies for Http Angularjs and Spring Boot article

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– AngularJS
– BootStrap

II. Overview
1. Project Structure

http angularjs spring boot - project structure

2. Step to do

– Create SpringBoot project
– Create a simple model
– Create a Controller
– Create a RestController
– Create a index.html page
– Create an angularjs controller with GET & POST methods
– Run & Check result

III. Practices
1. Create SpringBoot project

– Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, add project info, then press Next for needed dependencies:
For Template Engines, choose Thymeleaf
For Web MVC, choose Web->Web

angularjs-spring-boot-add-needed-dependencies

Open pom.xml file and check needed dependencies:

2. Create a simple model

Create a Customer model:

3. Create a Controller

– Create a simple controller for providing an index.html view

4. Create a RestController

Create a RestController with 2 RequestMapping:
GET request method that returns all customers.
POST request method that uses for adding a new customer.

5. Create an index.html page

Create a simple index.html page with a form for posting a customer to server, and a button for getting all customers from remote server.

User Bootstrap & Angularjs:

6. Create an angularjs controller with GET & POST methods

Create an angular controller file with 2 methods:
POST method to post a customer’s info to server with url: /postcustomer
$http.post(‘/someUrl’, data, config).then(successCallback, errorCallback);

GET method to get all customers from server with url: /getallcustomer
$http.get(‘/someUrl’, config).then(successCallback, errorCallback);

7. Run & Check result

Run Spring Boot Application and check result:
http angularjs spring boot result

IV. Sourcecode

SpringBootAngularJS


Related Posts


9 thoughts on “How to integrate Http Angularjs with Spring MVC | Spring Boot”

    1. Hi,

      You can do an http DELETE via an URL /customer/delete/{id} and AngularJs’s $http.delete function.

      In the Spring’s Controller, You need implement a new request mapping with annotation @DeleteMapping:

      Regards,

      1. Thank you!
        Although I still have some problems, could you help me out?
        I think something is still wrong with passing the path variable, i keep getting deleteResultMessage=”Failed”
        Here is my code:

        HTML:

        CONTROLLER.JS

        and RestWebCotroller:

          1. Ahhhhh, once i post the comment =my html code changes. Last attempt, of course in the programm i have “”:

          2. Hi,

            1. Firstly, please check again your url request:
            -> Your URL: var url = $location.absUrl() + "delete" + id;
            Correct is: var url = $location.absUrl() + "delete/" + id;

            2. Second:

            Default AngularJS with headers: 'Accept': 'application/json'
            Your controller returns a String format.

            -> Your’s Problem

            Solution:

    1. Hi,

      You can open a Eclipse Terminal by right click on the project -> Show in Local Terminal -> Terminal or Ctrl + Alt + T

      Then use the command-lines to build and run Spring Boot project: {mvn clean install, mvn spring-boot:run}

Got Something To Say:

Your email address will not be published. Required fields are marked *

*