当我遇到错误时,我很难让我的Spring MVC验证返回页面提交页面.我终于解决了这个问题,注意到BindingResult需要在我正在验证的表单参数旁边.
例如,如果我将spring.io教程(http://spring.io/guides/gs/validating-form-input/)中的checkPersonInfo方法修改为 -
@RequestMapping(value="/", method=RequestMethod.POST)
public String checkPersonInfo(@Valid Person person, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
return "form";
}
return "redirect:/results";
}
Run Code Online (Sandbox Code Playgroud)
然后它将工作并重定向到表单页面,但如果我将其更改为 -
@RequestMapping(value="/", method=RequestMethod.POST)
public String checkPersonInfo(@Valid Person person, Model model, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "form";
}
return "redirect:/results";
}
Run Code Online (Sandbox Code Playgroud)
然后它重定向到/ errors
这是什么原因?
我一直在试验Spring BOM并注意到有两个构建管理器 - spring-framework-bom和platform-bom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
要么
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>1.1.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
有什么不同?或者春天框架被取代了?我个人更喜欢spring-framework-bom方法,因为我可以控制弹簧版本?
我在我的网站上运行了Google PageSpeed Insights - www.gpsheatmap.com,它建议更改我的样式表(https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery#example)的加载-
<link href="/static/css/landing-page.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
至 -
<script>
var cb = function() {
var l = document.createElement('link');
l.rel = 'stylesheet';
l.href = '/static/css/landing-page.css';
var h = document.getElementsByTagName('head')[0];
h.parentNode.insertBefore(l, h);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else window.addEventListener('load', cb);
</script>
Run Code Online (Sandbox Code Playgroud)
我为我的样式表尝试了这个,它明显地改变了加载,所以你会看到pre-css视图,然后一秒钟你会看到应用样式表.这是在Firefox中
我应该忽视这种方法,还是可以解决这个问题?