为什么要在路径变量中添加用户名? 我认为您可以删除 onSubmit 属性并为操作添加 /profile 并使您的 http 动词在 form 和 controller 中发布。 您可以创建一个名为 profile 的对象,其中包含一个名为 username 的字段; 在您的控制器中的输入中添加 @ModelAttribute("profile")Profile 配置文件; 然后你可以在个人资料中获取用户名;像这样:
@PostMapping ("/profile")
public String profile(@ModelAttribute("profile") Profile profile) {