Guide on utilizing Spring MVC to accept an array as a parameter

Transform an array data structure into a JSON string by utilizing JSON.stringify

var nums = [3, 5];
let jsonNums = JSON.stringify(nums);
console.log(jsonNums);
axios.get('http://localhost/items', jsonNums).then(function (response) {
    if (response.code == 200) {
        console.log("Success");
    }
}

Observing parameters in transit through the Chrome browser console:

https://i.sstatic.net/V0LE9.png

An example of my items controller class:

@RequestMapping(value = "items", method = RequestMethod.GET)
public String removeByIds(@RequestBody Integer[] idList) {
    itemService.removeByIds(idList);
    return "ok";
}

Spring MVC seems to have difficulty processing arrays. Could this be an issue with how I've written the axios code? Any suggestions on how to resolve this?

Answer №1

After reviewing your inquiry,

axios.get('http://localhost/goods', json)

Since it is a get request, there will not be a body attached.

To address this issue, consider switching the method to post or utilizing @RequestParameter instead of @RequestBody.

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

Best practices for updating the value of a specific key within an object that contains recursion in JavaScript/TypeScript

I have a tree component that uses the following data structure type TreeNode = { id: string, parentId: string, renderer: () => React.ReactNode, expanded: boolean, children?: Array<TreeNode>, } Now, I am looking to add functionality for ...

What are the steps to increase or decrease the quantity of a product?

Is there a way to adjust the quantity of products in the shopping cart? I would like to be able to increase and decrease the quantity, while also displaying the current value in a span tag. <a href="javascript:" id="minus2" onclick="decrementValue()" ...

javascript unable to delete cookie

After conducting extensive research across various articles and links on deleting cookies using JavaScript, I have encountered an issue where the JavaScript code does not seem to be functioning as expected. The code I utilized for setting cookie values usi ...

Looking for some help with tweaking this script - it's so close to working perfectly! The images are supposed to show up while

Hey everyone, I'm struggling with a script issue! I currently have a gallery of images where the opacity is set to 0 in my CSS. I want these images to become visible when scrolling down (on view). In this script, I have specified that they should app ...

Highcharts 7 - Positioning an Annotation in the Center

I would like to display an annotation above specific data points on my Highchart. Currently, the annotation appears at the location of the data, but it is not centered directly over the point. I want the annotation to be perfectly centered on the data poin ...

The result after calling JSON.parse(...) was not accurate

The following method is used in the controller: @RequestMapping(value = "channelIntentionDetails.html", method = RequestMethod.POST) public @ResponseBody Report getChannelIntentionDetails(@RequestBody SearchParameters searchParameters) { LOGGER.in ...

Utilize the same Apollo GraphQL query definition across various Vue components for different properties

On my vue screen, I am trying to utilize a single apollo graphql query that I have defined for two different properties. From what I understand, the property name must correspond with an attribute name in the returned json structure. I attempted to use the ...

What is the best way to access a global variable within a store mutation function

I am encountering an issue with the vue-i18n dependency. How can I access the const i18n from main.js in root.js (store)? The technologies I am using include: Vuejs 2.X Latest version of Vue-i18n Vuex for Vuejs 2.X In main.js (vue-cli) Vue.use(VueI18 ...

What are some methods for monitoring time in PHP on the client and server sides?

I am in the process of developing an exam system using the Laravel Framework for PHP. The system will allow students to take exams within a specified time frame. For instance, if an exam is scheduled to start at 13:00 (my local time) and last for 2 hours, ...

Difficulty Communicating Recapcha 2 with the PHP Script

I am currently testing the installation of reCaptcha 2 with server-side verification using a form with one input field. My process involves sending the reCaptcha response via Ajax to a PHP page for verification. While I am able to capture the information p ...

Add another condition to the current JavaScript rule

http://jsfiddle.net/e8B9j/2/ HTML <div class="box" style="width:700px">This is a sentence</div> <div class="box" style="width:600px">This is a sentence</div> <div class="box" style="width:500px">This is a sentence</div> ...

The history.push function seems to be leading me astray, not bringing me back

Issue with History.Push in Register Component App function App() { const logoutHandler = () =>{ localStorage.removeItem("authToken"); history.push("/") } const [loading, setLoading]= React.useState(true) useEffect(()=>{ ...

The functionality of Change Detection is inconsistent when data is being received from the Electron Container IPC Channel

I have a program that is waiting for incoming information from an IPC Renderer Channel. Here is how I have it set up: container sending data to Angular app (mainWindow): mainWindow.loadURL('http://www.myangularapp.com') //location of the angul ...

The Angular scope remains stagnant even after applying changes

Having trouble updating a variable in the ng-repeat loop <div ng-controller="MapViewCtrl"> <a class="item item-avatar" ng-href="#/event/tabs/mapView" > <img src="img/location.jpg"/> <span cl ...

Exploring the options for accepting various file formats with Swal SweetAlert

Currently, I am using Swal Sweet Alert within my Vue.js application. I have successfully implemented code to allow image files, but now I am seeking assistance on how to extend this functionality to include multiple file types such as PDFs, PPTs, and Doc ...

Updating the state of an object within a mapping function

I've been struggling with this issue for two days now. Despite my efforts to find a solution online, I am still stuck and starting to believe that I might be missing something. The main functionality of the app is to click a button and watch an apple ...

Error encountered: Attempted to set invalid data in DocumentReference function. Value of field is not supported: undefined

Currently in the process of developing an e-commerce platform using Vue and Firebase. I am encountering an issue when attempting to add cart information for the logged-in user. Surprisingly, the information is saved perfectly on the initial attempt. Howeve ...

Guide on incorporating a hyperlink into a collection entity

My current setup involves a spring data repository structured like this: @RepositoryRestResource(collectionResourceRel = "items", path = "items") public interface ItemRepository extends CrudRepository<Item, Long> { } In addition to the standard rep ...

Converting Apache POI Word documents to clean HTML stripping out styles and superfluous tags

I am currently working on converting Word documents to clean HTML. I have been using Apache POI, but it seems to create messy output similar to MS Word's own HTML saving method. What I really need is a solution like the one offered by . For instance, ...

Tips for fixing the "Spring error: No converter for [class [B] with preset Content-Type 'image/png']" issue when attempting to display an image

Looking to create a spring controller that acts as a reverse-proxy for a geoserver instance. Essentially, the controller will forward requests from clients to the geoserver and serve back the response. When testing with an image URL, I encountered an erro ...