Springmvc passing and receiving array parameters

Source: Internet
Author: User

How to pass an array in the Java URL, how does the SPRINGMVC Framework controller class receive array parameters?

Here's how to pass an array parameter in a URL:

Dd.do?titles[]=col1&titles[]=col2&titles[]=col3

or using Ajax to pass:

var param = {titles:[ ‘col1‘ , ‘col2‘ , ‘col3‘ ]};  $.ajax({url: "dd.php" , type: "post" , data:param, async: false , dataType: "json" ,/**这个类型很重要 */ cache: false , error: function (data) {           rtnObj = data.responseText;       }, beforeSend: function (XMLHttpRequest) {           //ajaxStart();       }, complete: function (XMLHttpRequest, textStatus) {           //ajaxComplete();       }, success: function (data) {           rtnObj = data;       }});

In Springmvc, the controller class receives array parameters in the method:

@RequestMapping (value= "/save" , method = RequestMethod.POST)  @ResponseBody public String save( @RequestParam (value = "titles[]" ) String[] titles){       System.out.println(titles);       return null }

Springmvc passing and receiving array parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.