Discover the process of connecting a REST controller with AngularJS and Spring

I have a list of file paths stored in an array within the scope variable of an AngularJS Controller.

My goal is to properly map these file paths to a Java REST controller for further processing.

When I pass it as "/ABC/Scope-Variable," it successfully matches the REST controller by interpreting Scope-Variable as a string.

However, when I attempt to use "/ABC/+Scope-Variable," due to the presence of slashes and an array in the file path, I am unable to map it to the Java REST controller.

Any assistance is greatly appreciated.

Thank you

Answer №1

To begin, we must establish a suitable controller in the Spring framework.

MySpringController.java:

@Controller
public class MySpringController {

    @RequestMapping(value = "/updateItems", method = RequestMethod.POST)
    public List<String> updateItems(@RequestBody List<String> updatedItems) {
       System.out.println(updatedItems);
       // perform necessary actions
       return null;
    }
}

Afterwards, in your JavaScript file, implement something similar to this:

MyAngularFile.js:

$scope.items = ['path1.jpg', 'path2.jpg', 'path3.jpg'];
$http.post('http://myserver:8080/updateItems', $scope.items).then(function(response) {
        console.log('Successfully posted items!');
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determining the Right Version of a Framework in npm: A Guide

One common issue I encounter is the uncertainty of which versions of npm, Ionic, and other tools I should have installed. It often goes like this: "Oh, there's a new version of the Ionic CLI out. Let's update." I install CLI v3.9.0. ...

Setting header details for optimal data transfer

Currently, there is a Java code snippet that I am working on which attempts to access the header information sent by an HTML page. Unfortunately, I do not currently have the specific HTML page in question. However, I still need to be able to access and m ...

Activate a button utilizing jQuery keyboard functionality

Here is what I have accomplished so far: http://jsfiddle.net/qEKfg/ I have created two buttons that activate on click and resemble keyboard keys. My goal is to make them animate only when the corresponding keys (CTRL and ...

Are we utilizing this JavaScript function properly for recycling it?

Two functions have been implemented successfully. One function adds the autoplay attribute to a video DOM element if the user is at a specific section on the page. The other function smoothly slides in elements with a transition effect. The only limitatio ...

Error: React Select input control is throwing a TypeError related to event.target

Having trouble changing the state on change using a React Select node module package. It works with regular text input, but I can't quite get it to work with this specific component. The error message "TypeError: event.target is undefined" keeps poppi ...

Secure multiple confirmations with ngDialog

When using the ngDialog popup window to collect data into a $scope array, I encountered an issue where if a user clicks the confirm button multiple times, the data gets added multiple times. I attempted to use ngDisable with a $scope variable to disable ...

Introducing the new default in Google Chrome: Now accessing window.opener for target="_blank" links after rel="noopener" is the standard feature

Exploring a new attribute called rel="noopener", I discovered that it keeps opened windows unaware of their opener. After some experimentation, I consistently found window.opener === null, only to realize that this is now the default behavior in ...

spark of unique substance

Having trouble with cycle2 as all images are briefly displayed when the page loads. I tried the recommended solution http://jquery.malsup.com/cycle/faq.html but it didn't stop the flashing, indicating a different issue: The suggested fix for Cycle is ...

Adjust the color of text in Angular as you input text

Here is my setup: <input type="number" ng-model="myNumber"> $scope.$watch('myNumber', function(nV, oV) { $scope.myNumberPlus10 = (nV + 10); }); <span>{{ myNumberPlus10 }}</span> I want the text color of <span>{{ myN ...

Using nodeJS to authenticate with Active Directory

Currently, my company is focusing on developing an AngularJS web app that interacts with a C#.Net REST API to retrieve all necessary data. The application users are required to log into Windows computers that are connected to an Active Directory, allowing ...

Click on the link or tab to update the marker location on the Google Map

Can you click on Tab 2 to change the marker/location, and then go back to Tab 1 to switch it back to the original location? [Links to Fiddle] http://jsfiddle.net/ye3x8/ function initialize() { var styles = [{ stylers: [{ saturati ...

What is the best way to invoke a method within a method in Angular 1.x?

Here is a breakdown of my HTML structure: Controller Side: <div ng-controller="Ctrl"> <first-directive></first-directive> </div> First Directive HTML: <li> <second-directive></second-directive> </li> C ...

I'm having trouble figuring out how to access response headers with HttpClient in Angular 5. Can anyone

I recently developed an authentication service in Angular 5, where I utilize the HttpClient class to make a POST request to my backend server. The backend server then responds with a JWT bearer token. Here is a snippet of how my request looks: return thi ...

How can I avoid C3.js legends from overlapping when hiding or showing a div?

Every time I visit a specific page, a simple chart is automatically generated: function displayOptions() { $("#div1").show(); chartRef.flush(); } function displayChoices() { $("#div1").show(); } $("#div1").hid ...

Is there a way to make Express.js pass parameters with special characters exactly as they are?

I am currently working on a project within the freeCodeCamp "API and Microservices" curriculum that involves using Express.js to handle routes. The project itself is relatively straightforward, with some pre-defined routes and others that need to be creat ...

Troubleshooting: Height setting issue with Kendo UI Grid during editing using Jquery

Issue: My Kendo UI JQuery Grid is fully functional except for a bug that occurs when adding a new record. When I add and save a new record, the grid's footer "floats" halfway up the grid and the scrollbar disappears, making it look distorted. Furth ...

Searching for JSON data in JavaScript

Is there a more efficient approach for searching data in JSON other than using loops? This is specifically for editing and deleting purposes. for(var k in objJsonResp) { if (objJsonResp[k].txtId == id) { if (action == 'delete') { obj ...

log4j failing to display logs in selenium testing

I am having trouble with logging automation using log4j. The logs file is being created but the logs are not being printed in the log file. Here is my log4j.properties File: #Root logger option log4j.rootLogger=debug, file log4j.appender.file=org.apache. ...

Finding a path match with Regexp using path-to-regexp

When obtaining a user's information by their unique id: /user/{id} I convert this path to a regular expression: pathToRegexp(path.replace(/\{/g, ':').replace(/\}/g, '')) Next, I compare it with: const matchedPaths = ...

The FaceDetector within the expo application continues to activate the "onFacesDetected" event in "accurate" mode unnecessarily, even when no face is present

Just starting out with react native and I've been exploring the use of expo FaceDetector for detecting faces. In "fast" mode, the "onFacesDetected" event is triggered correctly. However, when switching to "accurate" mode, the "onFacesDetected" event k ...