• 前后端接口传输参数方式 post(json, formdata) get


    方式一:前端以json串的方式传输, post请求

    getCopyCourseInfo(
            this.form
          ).then(response => {
            this.courseList = response.data
            this.isresult = true
          })

      接口post的请求方式:

    export function getCopyCourseInfo(data) {
      console.log('data = ', data)
      return request({
        url: '/course/getCopyCourseInfo',
        method: 'post',
        data
      })
    }
    

      服务端接口接收方式

     @PostMapping(value = "/getCopyCourseInfo")
        public ResponseMessage getCopyCourseInfo(@RequestBody JSONObject request){
        String courseId = request.getString("courseId");
    }
    

      

    方式二:  以参数的形式传递 post请求 formdata

    getIdByActivity({
            discountActvId: this.discountActvId, env: this.form.env, cookie: this.form.cookie
          }).then(response => {
            const res = response.data
            this.renewId = res
          })
    
    export function getIdByActivity(data) {
      return request({
        url: '/course/getIdByActivity',
        method: 'post',
        params: data
      })
    }
    

      服务端请求方式 post请求  formdata的形式

    @RequestMapping(value = "/getIdByActivity")
        public Object getIdByActivity( @RequestParam String env,@RequestParam Integer discountActvId, @RequestParam String cookie)
    

     方式三: get 方法

    getStudentMhdHeader({ showBuyCourses: this.showBuyCourses, showAttendance: this.showAttendance }).then(response => {
            this.tableData = response.data
            console.log('this.tableData=', this.tableData)
            this.getList()
          })
    

      

    export function getStudentMhdHeader(query) {
      return request({
        url: '/studentMhd/getHeader',
        method: 'get',
        params: query
      })
    }
    

      

    @GetMapping("/getHeader")
        public ResponseMessage getHeader(@RequestParam(required = false) Boolean showBuyCourses,
                                         @RequestParam(required = false) Boolean showAttendance)
    

      

     

      

  • 相关阅读:
    SpringBoot项目中遇到的BUG
    关于Unsupported major.minor version 52.0报错问题解决方案
    spring官网上下载历史版本的spring插件,springsource-tool-suite
    构建微服务:Spring boot 入门篇
    Spring Cloud 入门教程(一): 服务注册
    SpringCloud是什么?
    ubuntu下查看windows的 txt 文件乱码
    Ubuntu 14.04 LTS中怎样安装fcitx中文输入法
    eclipse调用jni
    Ubuntu 12.04 分区方案(仅供参考)
  • 原文地址:https://www.cnblogs.com/leavescy/p/14558871.html
Copyright © 2020-2023  润新知