第一种方法
在vue项目中更改,使用 new URLSearchParams()构造参数,将参数放到里面,发起请求时直接将params传递到服务器即可
let params = new URLSearchParams();
params.append("account",this.loginForm.account)
params.append("password",this.loginForm.password)
const {data:res} = await this.$http.post("/user/login",params)
第二中方法
将控制层接收的参数改为Map
public JsonData loginValid(@RequestBody Map map){
AccountInfomation accountInfomation = new AccountInfomation();
accountInfomation.setPassword((String) map.get("password"));
accountInfomation.setAccount((String) map.get("account"));
AccountInfomation AccountInfomationVO = acountService.loginValid(accountInfomation);
if (AccountInfomationVO != null){
return JsonData.buildSuc(AccountInfomationVO);
}
return JsonData.buildError("登录失败");
}
第三种方法
第三种方法也是最根本的方法,由于axios默认发送数据时,数据格式是Request Payload,而并非我们常用的Form Data格式,后端数据接收不到,所以在发送之前,需要使用qs模块对其进行处理。
首先需要安装qs
npm install qs
然后在main.js中导入并挂载到Vue对象上
import qs from 'qs'
Vue.prototype.$qs = qs
然后·在请求的时候处理一下参数即可
const {data: res} =await this.$http.post("/student/saveStudentInfo",this.$qs.stringify(this.saveStudentRuleForm))