简体   繁体   中英

for redirecting the different page on button submit with array to spring Controller()

on click on button(submitButton)

create a hidden from and I have sent the data, suppose my data is [60,56]

     assetGroupId: [60,56]

$("#submitButton").click(function() {
    console.log("submit button is calling");

     var assetID= JSON.stringify(assetGroupId);
document.body.innerHTML += '<form id="assetIdForm" action="http://localhost:9007/abcd" method="post">
            <input type="hidden" name="assetID" value="assetID"></form>';
document.getElementById("assetIdForm").submit();

my controller is:

   @RequestMapping(value = "/abcd", method ={ RequestMethod.POST, RequestMethod.GET },produces=MediaType.APPLICATION_JSON_VALUE,
                                            consumes=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ModelAndView getvalue(String[] ID) {
}

In my controller i need to get the data is [50,60], but i am getting I,D. kindly help me.. how i can get data in controller.

try this

document.body.innerHTML += '<form id="assetIdForm" action="http://localhost:9007/abcd" method="post">
        <input type="hidden" name="assetID" value="'+assetID+'"></form>';

document.getElementById("assetIdForm").submit();

assetID as a variable inside value tag

在HTML中使用名称作为数组name="assetID[]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM