0
我正在學習scalate模板引擎。如何將我的控制器中的對象(例如用戶)傳遞到我的Scalate模板中的模板.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";
}
感謝您效應初探。我編輯了我的帖子,併發布了我的控制器。正如你可以看到我回來的模板名,所以我不知道如何將這與你的方法:( – Fixus 2012-03-17 18:57:02
@Fixus更新的答案。 – ebaxt 2012-03-17 19:02:02
你是awsome。你解決了我的問題與模板。但我仍然得到例外:/ org.springframework.web.util.NestedServletException:請求處理失敗;嵌套異常爲org.fusesource.scalate.CompilerException:編譯失敗: /WEB-INF/scalate/defaultTemplate.ssp:3.13錯誤:找不到:type User <%@ var user:User%> – Fixus 2012-03-17 19:07:35