axios向后台发送post请求时关于参数传递的方式总结
分类:计算机 | 前端 | 综合 1048
更新:2022-02-09 23:13:16编辑
最近在使用axios向后台服务发送post请求时发现后台接口接收到的前端参数都是null。
后台接口如下:
@PostMapping("/chaoqianit/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
{
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
Subject subject = SecurityUtils.getSubject();
......
}
网上查了一下了解到,出现参数为null的情况是因为axios发送post请求时的参数格式不对,对于这样的后台接口,前端应该这样写:
var params = new URLSearchParams();
params.append('username', this.ruleForm.username);
params.append('password', this.ruleForm.password);
params.append('validateCode', this.ruleForm.validatecode);
params.append('rememberMe',true);
axios.post("/chaoqianit/login", params)
.then(function(res) {
})
.catch(function(error) {
that.$message.error("登录失败!");
});
参考资料
https://jingyan.baidu.com/article/29697b916d6a7bab20de3cf9.html
猿导航
阅读排行榜
- 1vue和el-table使用经验-如何刷新表格数据10961
- 2three.js加载3D瓦片和3dtiles数据生成交互式地图的开源项目9509
- 3Microsoft Visual C++ Redistributable是什么,有什么作用?7287
- 4mybatis使用经验——mybatis-spring-boot-starter和mybatis的版本对应关系表(持续更新~)5869
- 5uni-app使用经验—vue页面和html页面如何互相调用接口并传参5489
- 6Intellij IDEA下的版本控制VCS的启用与关闭4922
- 7Spring学习经验—@ResponseBody注解的使用说明4907
- 8Druid异常解决经验—java.sql.SQLException url not set4522
- 9如何用批处理命令(bat脚本)启动和停止windows服务4301
- 10nuxt.js项目中如何添加和使用全局变量4165
- 11解决SpringBoot使用maven下载不了jar包的问题3502
- 12linux中解压tar.gz文件报错“gzip: stdin: invalid compressed data--format violated”3405
- 13nuxtjs asyncData使用经验—如何发起多个axios请求并携带参数3251
- 14在Nuxt.js项目的head中引用外部js文件3095
- 15在NVIDIA控制面板设置参数时提示“拒绝访问 无法应用选定的设置到您的系统”的解决方法之一3072