2012-03-17 6 views
0

私はscalateテンプレートエンジンを学習しています。コントローラからオブジェクト(例:User)をスケーラビリティテンプレートのテンプレート.sspに渡すにはどうすればいいですか?sprintの属性をscalateテンプレートに渡すにはどうしたらいいですか?

私のコントローラ

@RequestMapping(value = "/", method = RequestMethod.GET) 
public String home(Locale locale, Model model) { 
    logger.info("Welcome home! the client locale is "+ locale.toString()); 

    Date date = new Date(); 
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); 

    String formattedDate = dateFormat.format(date); 

    model.addAttribute("serverTime", formattedDate); 

    User user = new User("Dawid", "Pacholczyk"); 

    model.addAttribute(user); 

    return "defaultTemplate"; 
} 

答えて

1

私はあなたがこのようにそれにパラメータを渡すことができますねViewResolver使用して実装されている春のサポートを考える:

val response = new ModelAndView 
    response.addObject("user", new User) 
    return response 

も同様spring exampleを見てください。

編集:

あなたはとても似のModelAndViewを返す必要があります。

@RequestMapping(value = "/", method = RequestMethod.GET) 
public ModelAndView home(Locale locale, Model model) { 
    ... 
    User user = new User("Dawid", "Pacholczyk"); 
    template = new ModelAndView("defaultTemplate"); 
    template.addObject("user", user); 
    return template; 
} 
+0

はREPONSEしていただきありがとうございます。私は私の投稿を編集し、私は自分のコントローラを投稿しました。あなたが見ることができるように私はテンプレート名を返すので、これをあなたのメソッドと組み合わせる方法は分かりません:( – Fixus

+0

@Fixus updated answer。 – ebaxt

+0

あなたは素晴らしいです。あなたは私の問題をテンプレートで解決しました。 :/ org.springframework.web.util.NestedServletException:リクエストの処理に失敗しました。ネストされた例外はorg.fuseource.scalate.CompilerExceptionです:コンパイルに失敗しました: /WEB-INF/scalate/defaultTemplate.ssp:3.13エラー:見つからない:type User <%@ var user:User%> – Fixus