:春MVC&ベロシティ:私は、テンプレートのこの種の機能を実現したいテンプレートの構造
- は、ヘッダー、フッター、および完全な(X)HTMLウェブページ
- の共通部分を定義するテンプレートを持っています
:
@Controller
から文字列を返すことは、それはビューは次のようにテンプレート
の特定の部分に含ま定義します
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home_view";
}
ビュー/ home_view.vm
<h2>Content title</h2>
<p>Content text</p>
ビュー/ template.vm
<html>
<head>
<title></title>
</head>
<body>
<!-- Header of page -->
#include({context variable which contains "home_view"} + ".vm");
<!-- Footer of page -->
</body>
</html>
誰もがCakePHPのを知っている場合、これはそのテンプレートに似て@Controllerシステム
どうすればいいですか?
アスペクトを使用する場所になる可能性があります。すべてのコントローラを '@ RequestMapping'アノテーションでターゲットにし、メソッドを' template.vm'を返すものでラップし、 'home_view.vm'を' Model'に置きます。ここで 'template.vm'はそれを抜き出して含める。それ以外の場合は、DispatcherServlet - http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/DispatcherServlet.html#resolveView%%28java.lang.Stringをオーバーライドできます。 %20java.util.Map、%20java.util.Locale、%20javax.servlet.http.HttpServletRequest%29 –
@PaulGrimeしかし、それはすべての単一のページが単一のコントローラインスタンスを持たなければならないことを意味するでしょうか?しかし、私はそれが優先されるのが好きです。 –
'template.vm'以外のものを返す場合は、yesを返します。 –