zoukankan      html  css  js  c++  java
  • 前台传数据给后台的几种方式

    1.后台接收方式为@RequestBody(后台接收多个数据)

    前台需要将数据转换为json格式

    首先前台数据以对象形式存放:

             data:{
                    sex:'',
                    type:'',
                    result:'',
                    name:'',
                    meaning:''
                },  


    data中的数据可以通过:this.data.hobby = ''添加
    通过delete this.data.hobby删除

    之后通过

    JSON.parse(JSON.stringify(this.data))

    将data转换为json格式

    最后通过post传给后台

                http({
                        url:'/data/add',
                        method:'post',
                        data:JSON.parse(JSON.stringify(this.data))
                    }).then(res=>{
                       console.log(res);
                    })        

    2.后台接收String格式数据(只需要接收单个数据)

          http({
                 url:'/data/del',
                 method:'post',
                 params:{id:this.id,name:this.name}
            }).then(res=>{
                 console.log(res)
            })
          }

    3.前台传list给后台

          let arr = []
              let i = 0
          (list为Object类型  List<Object>)
           this.result.forEach(element => { arr[i] = { id:this.id, name:element.name, suggest:element.suggest } i++ })
          
        (list为String类型  List<String>)
          this.result.forEach(element => {
                arr[i] = this.id,
                 
                i++
              })
        http({ url:'/dic/add', method:'post', headers: { 'Content-Type': 'application/json;charset=UTF-8' }, data:JSON.stringify(arr) }).then(res=>{ console.log(res); })
  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/brillant/p/15813497.html
Copyright © 2011-2022 走看看