1

私はscalateテンプレートエンジンを学んでいます。オブジェクト (ユーザーなど) をコントローラーから scalate テンプレートのテンプレート .ssp に渡すにはどうすればよいですか?

私のコントローラー

@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";
}
4

1 に答える 1

1

SpringのサポートがViewResolverを使用して実装されていることを考えると、次のようにパラメーターを渡すことができると思います。

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

春の例も見てください。

編集:

次のように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;
}
于 2012-03-17T18:52:03.150 に答える