すべてのhtmlページを準備してプロジェクトを開始しています。ですから、今はすべてのコントローラを作成してリクエストを処理し、ビューを表示する必要があります。すべてのコントローラを作成する前に、ルートに対応するビューを取得する「汎用」コントローラを用意することはできますか?Spring MVCがマップされていないリクエストを処理する
たとえば、私はspring mvc + thymeleafを持っています。だから
@RequestMapping(value = "/", method = RequestMethod.GET)
public String login(Model model) {
return "authentication/login.html";
}
私は「ジェネリックを持つことができます:私が作成した最初で唯一のコントローラである
private ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("/WEB-INF/templates/");
resolver.setTemplateMode(TemplateMode.HTML);
return resolver;
}
:私は、リゾルバとのWebContent/WEB-INF /テンプレートですべての私の.htmlを持っています'コントローラは、残りの要求を処理するので、' http://localhost:8080/authentication/register.html 'と書くと、ジェネリックコントローラは' authentication/register.html 'のビューを取得します。
あなたは[this](http://forum.spring.io/forum/spring-projects/web/19404-how-to-map-urls-to-jsps-without-the-custom-コントローラ) – AntJavaDev
@AntJavaDev 'UrlFilenameViewController'を拡張し、' postProcessViewName'をオーバーライドしています。 Springはクラスを無視します。 – angeldev