gpt4 book ai didi

Java Spring MVC 如何获取这个设定值?

转载 作者:行者123 更新时间:2023-12-02 12:28:58 26 4
gpt4 key购买 nike

如何通过 GET 方法获取已设置的值?如何将值传递给 POST 方法?我应该声明全局变量吗?

编辑:我想要的是在 GET 方法上做一些事情,如果 setdisplayBox = true,则在 jsp 上显示一个文本框。当用户 POST 表单时,setdisplayBox 也应该为 true 并返回相同的 jsp 而无需重定向

@RequestMapping(method = RequestMethod.GET)
public String getSuccess(ModelMap model, @ModelAttribute("user") User user, HttpServletRequest request)
{
String boxDisplay = "True";
user.setdisplayBox(boxDisplay);
return "success";
}

@RequestMapping(method = RequestMethod.POST)
public String resetPassword(HttpServletRequest request, ModelMap model, @ModelAttribute("user") User user, ModelMap modelMap)
{
user.setdisplayBox(user.getdisplayBox()); //how to get value has been set above?
return "success";
}

最佳答案

为用户设置全局变量。

private User userAccount;

@RequestMapping(method = RequestMethod.GET)
public String getSuccess(ModelMap model, @ModelAttribute("user") User user, HttpServletRequest request)
{
String boxDisplay = "True";
user.setdisplayBox(boxDisplay);
userAccount = user; //load user in to global var
return "success";
}

@RequestMapping(method = RequestMethod.POST)
public String resetPassword(HttpServletRequest request, ModelMap model, @ModelAttribute("user") User user, ModelMap modelMap)
{
user.setdisplayBox(userAccount.getdisplayBox());
userAccount = null; //reset it to something to make sure you are loading it to another user later.
return "success";
}

关于Java Spring MVC 如何获取这个设定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45377236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com