get请求如何发送JSON数据,后端如何接收get请求Json数据

1、前端如何通过get请求发送Json数据,需要用到qs库,qs.stringify( jsondata, { arrayFormat: "repeat" }) 对数据进行转化。

2、后端如何接收get请求的Json参数,需要使用@ModelAttribute注解可以自动把参数转化为实体类对象。

 

前端代码:

// 下载文件
export const downloadExcel = (data) => {
  return downloadFile(`${URL_PREFIX}/${modelName}/downloadExcel?${qs.stringify(data, { arrayFormat: "repeat" })}`,"文件.xlsx")
};

后端代码:

   /**
     * 下载excel
     */
    @GetMapping("/downloadExcel")
    public void download(@ModelAttribute DataReq request, HttpServletResponse response ) {

    xxx....

}

 

posted @ 2024-09-10 15:42  一文搞懂  阅读(63)  评论(0编辑  收藏  举报