关注this guide我已经配置了一个控制器来处理一个非常简单的表单的显示和验证。我正在使用Thymeleaf th:href链接到表单。
<a th:href="@{/event/create}">Create Event</a>
问题是,单击链接后,一个接一个地调用showForm()和checkEventForm()。结果是从表单快速重定向回到/,因为checkEventForm()也被处理。
是否要处理GET和POST?
链接:
<div id="sidebar">
<ol>
<li><a th:href="@{/}">Join Event</a></li>
<li><a th:href="@{/event/create}">Create Event</a></li>
</ol>
</div>
MvcConfig:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.setCachePeriod(31556926);
}
}
CreateEventController:
@Controller
public class CreateEventController {
@RequestMapping(value="/event/create", method=RequestMethod.GET)
public String showForm(CreateEvent event) {
return "createEvent";
}
@RequestMapping(value="/event/create", method=RequestMethod.POST)
public String checkEventForm(@Valid CreateEvent event, BindingResult bindingResult){
if(bindingResult.hasErrors()){
return "createEvent";
}
return "redirect:/";
}
}
答案 0 :(得分:0)
经过一番挖掘后,我的程序根本就没有了!它实际上是一个chrome扩展(lastpass),它有一个自动保存的localhost密码,它试图自动登录并提交表单!谈论让自己疯狂!