gpt4 book ai didi

java - Spring 形式什么也不做

转载 作者:太空宇宙 更新时间:2023-11-04 13:00:09 25 4
gpt4 key购买 nike

我正在尝试更新用户设置信息。当我点击提交时,没有任何反应。

这是我的设置 Controller

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@RequestMapping(value = "/settings**", method = RequestMethod.GET)
public ModelAndView settings() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = auth.getName();
User userInfo = userDAO.getUserInfo(userName);
Settings settings = userDAO.getSettingsInfo(userInfo.getDetails().getMacAddress());
List<Plugs> plugs = userInfo.getDetails().getPlugs();
ModelAndView model = new ModelAndView();
model.addObject("settings", settings);
model.addObject("plugs", plugs.get(plugs.size() - 1));
return model;
}

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@RequestMapping(value = "/settings", method = RequestMethod.POST)
public ModelAndView settings(@Valid @ModelAttribute("settings") Settings settings, BindingResult result) {
ModelAndView model = new ModelAndView();
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = auth.getName();
User userInfo = userDAO.getUserInfo(userName);
if (result.hasErrors()) {
model.setViewName("welcome");
} else {
model.setViewName("settings");
userDAO.updateSettings(userInfo);
}

return model;
}

JSP 表单

<form:form method="POST" modelAttribute="settings" commandName="settings">

这是我的提交按钮

<input type="submit" value="submit" name ="submit">

如何让我的表单执行任何操作?它应该更新 MySQL 数据库中的用户详细信息。如果您想发布更多代码,我会添加它。

最佳答案

您可以尝试在表单标签中添加action属性吗?

<form:form method="POST" modelAttribute="settings" commandName="settings" action="/settings">

如果您的 Springframework DispatcherServlet servlet 映射的 url 模式不是 web.xml 中的“/”,请将该模式附加在“/settings”之前,如下所示:

<form:form method="POST" modelAttribute="settings" commandName="settings" action="{url pattern}/settings">

关于java - Spring 形式什么也不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35009937/

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