axios默认是application/json方式提交,controller接收的时候必须以@RequestBody的方式接收,有时候不太方便。如果axios以application/x-www-form-urlencoded方式提交数据,controller接收的时候只要保证名字应对类型正确即可。
前端代码:
<el-dialog
v-model="dialogVisible" width="30%"
>
<el-form :model="formData" label-position="top">
<el-form-item label="用户名">
<el-input v-model="formData.username" placeholder="用户名..."/>
</el-form-item>
<el-form-item label="密码">
<el-input type="password" v-model="formData.password" placeholder="密码..."/>
</el-form-item>
</el-form>
<template v-slot:header>
<span>登录窗口</span>
</template>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="formConfirm">
登录
</el-button>
</span>
</template>
</el-dialog>

本文介绍了如何在前端使用axios以application/x-www-form-urlencoded方式提交数据,以及后端Controller如何直接接收并处理这种形式的表单数据,包括使用Element-Plus组件和SpringBoot的@PostMapping处理示例。
最低0.47元/天 解锁文章
2567

被折叠的 条评论
为什么被折叠?



