javascript - Reactjs AXIOS Put 请求
问题描述
我有一个想要从后端更改的前端用户。所以我做了一个AXIOS查询,但它不起作用。
async updateUtilisateur(user) {
const headers = {
'authorization': localStorage.getItem(ACCESS_TOKEN)
}
const {id} = user.id;
return await axios.put('/secure/utilisateur/${id}',
user,{headers}
);
},
在我的后端日志中:osswumatcher.AntPathRequestMatcher:检查请求匹配:'/secure/utilisateur/${id}'; 反对'/gestion-promotions/secure/**'
2018-12-19 22:21:19.018 WARN 1432 --- [io-8080-exec-14] .wsmsDefaultHandlerExceptionResolver: 已解决 [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: 无法转换类型“java”的值。 lang.String' 到所需类型'java.lang.Integer';嵌套异常是 java.lang.NumberFormatException: For input string: "${id}"]
id 在我的请求中是一个 PathVariable
解决方案
您在此行中使用了错误类型的引号:
return await axios.put('/secure/utilisateur/${id}',
您正在使用 ''(单引号)而不是 ``(反引号) 这导致您的变量id
未正确插值,然后您将字符串发送${id}
到后端。
要解决此问题,您可以使用反引号:
return await axios.put(`/secure/utilisateur/${id}`,
或者:
return await axios.put('/secure/utilisateur/' + id,
有关 javascript 中反引号的更多信息:模板文字
推荐阅读
- unity3d - 我可以使用 RiftCat 玩我的统一 VR 应用吗
- r - Betareg 摘要导致内存分配错误
- javascript - JavaScript - SCRIPT1028:预期的标识符、字符串或数字错误
- ldap - windows 10 php 7.4.8 启用 LDAP 模块未激活
- vue.js - 如何将自定义域代理到 vuejs 应用程序?
- javascript - 高清录制 - Ziggeo Recorder v2 JS
- javascript - React-Redux 问题。找不到变量 mapDispatchToProps
- javascript - 如何将其他项目添加到存储数组并且在重置时仍然能够将数组设置为空?
- sql - 检查 2 个表是否有相同的 ID,如果表 1 中的 ID 存在于表 2 中,则在列中返回 1/0
- python - 文本到列熊猫