【发布时间】:2018-12-29 03:09:01
【问题描述】:
我正在研究spring框架,并在网上学习了一些教程,然后我发现了这个:
package control;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MVCController implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
registry.addViewController("/").setViewName("index");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
}
所以我的疑问是:
如何在不添加新行的情况下添加更多页面以将视图控制器添加到每个页面?
有什么方法可以将一些通用控制器放到我不打算进行一些处理的页面上? (例如一些静态页面)
我使用的是 spring 5 和 Java JRE 1.8。
谢谢!
【问题讨论】:
标签: java spring spring-mvc spring-boot