第十九章 SpringMVC其它配置

来源:互联网 发布:何玉洁数据库第四版 编辑:程序博客网 时间:2024/05/29 16:49

快捷的ViewController

我们在之前的页面转向代码为

@RequestMapping("/index")public String index() {    return "index";}

此处无任何业务,只是单纯的页面转向,实际开发中存在大量这样的页面转向,可以通过在配置中重写addViewControllers方法来简化配置

@Overridepublic void addViewControllers(ViewControllerRegistry registry) {    registry.addViewController("/index").setViewName("/index");}

路径匹配参数配置

在SpringMVC中,路径参数如果带“.”的话,“.”后的值将会被忽略,例如访问”…/name/xx.yy”,此时yy会被忽略,通过重写configurePathMatch方法可以不忽略“.”后面的参数

@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {    configurer.setUseSuffixPatternMatch(false);}

WebMvcConfigurer中提供了不少方法供扩展,可以自行研究每一个方法的作用。

0 0