You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从不同页面跳转交易接口时丢失userId参数的问题排查

问题原因分析与解决方法

核心问题

钱包页面的Transactions链接丢失userId参数,根源在于钱包页面的控制器没有将用户ID传递到Thymeleaf模板中,导致模板里的${userId}变量为空,生成URL时无法填充参数。

对比验证

  • 首页控制器:主动通过model.addAttribute("userId", userId);将用户ID存入Model,模板能正常获取${userId}生成完整链接。
  • 钱包页面控制器:仅向Model添加了wallet和wallets属性,没有传递用户ID相关变量,模板中的${userId}无值,最终URL缺失参数。

解决方案

修改钱包页面的控制器,将user_id参数添加到Model中,确保模板能获取到用户ID:

@GetMapping("/userWallet/balance/{user_id}")
@PreAuthorize("#user_id == authentication.principal.id")
public String getUserWallet(@PathVariable(value = "user_id") Long user_id, Model model) {
    model.addAttribute("wallet", walletService.findDistinctIdByUserId(user_id));
    model.addAttribute("wallets", walletService.netWorth(user_id));
    // 新增该行,将用户ID传递到模板
    model.addAttribute("userId", user_id);
    return "user_profile";
}

修改后,钱包页面的Thymeleaf链接@{/api/transaction/userTransactions/{userId} (userId=${userId})}就能正常获取userId值,生成完整的带参数URL。

内容的提问来源于stack exchange,提问作者Frosty Nah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 11:28:06