欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

play!之旅 (一) play!框架可以做的五件华丽丽的事情 3

程序员文章站 2022-04-18 11:46:56
...

这个我不翻译了,我不能理解这点,虽然说可以直接传参数,可是传统的servlet不是也可以分别放入request对象内么,看不出什么实质的区别 哪位大侠知道的指点小弟以下

3. Don’t Repeat Yourself when passing Java objects to templates

In most Java frameworks, in order to pass Java objects to the template system you need to write something like:

Article article = Article.findById(id);
User user = User.getConnected();
Map<String, Object> model = new HashMap<String,Object>();
model.put("article", article);
model.put("user", user);
render(model);

With play, you can just write:

Article article = Article.findById(id);
User user = User.getConnected();
render(article, user);

And retrieve objects from their Java local name in the template. That saves a lot of useless lines of code...