zoukankan      html  css  js  c++  java
  • springMVC绑定json参数之二(2.2.2)

    二、springmvc 接收不同格式的json字符串

    2).格式二:json字符串数组

    前台:

    test = function () {
            
            
                    var  test = ["123","qwe","asd"];
    
                    jQuery.ajax({  
                        url : cur_url+"/weekly/test",  
                        type : 'post',  
                        data : JSON.stringify(test),  
                        dataType : 'json',
                        contentType:'application/json;charset=utf-8',
                        success : function (data, textStatus) { 
                            console.info(data);
                            alert("test success!");
                        },
                        error:function(){
                            alert("test error!");
                        }
                    });
        };

    后台接收:

            @RequestMapping("/test")
            @ResponseBody
             public List<String> test(@RequestBody String[] strs ) {
               for (String s : strs) {
                System.out.println(s);
               }
            
               return Arrays.asList(strs);
                
          }

    3).格式三:json 数字组成的数组
    前台发送:

    test = function () {
            
            
                    var  test = [1231,4562,7893];
    
                    jQuery.ajax({  
                        url : cur_url+"/weekly/test",  
                        type : 'post',  
                        data : JSON.stringify(test),  
                        dataType : 'json',
                        contentType:'application/json;charset=utf-8',
                        success : function (data, textStatus) { 
                            console.info(data);
                            alert("test success!");
                        },
                        error:function(){
                            alert("test error!");
                        }
                    });
        };

    后台接收:

    @RequestMapping("/test")
            @ResponseBody
             public List<Integer> test(@RequestBody Integer[] strs ) {
               for (Integer s : strs) {
                System.out.println(s);
               }
            
               return Arrays.asList(strs);
                
          }
  • 相关阅读:
    webview学习
    Android中webview html5 自动播放本地视频
    Android中使用WebView实现全屏切换播放网页视频
    Android中实现Activity的透明背景效果
    App过大
    Android 9.0网络权限适配
    Android中自定义环形图2
    Android中自定义环形图
    Android中自定义水球
    vue学习指南:第五篇(详细)
  • 原文地址:https://www.cnblogs.com/cainiao-Shun666/p/6768012.html
Copyright © 2011-2022 走看看