jeudi 28 mai 2015

Do I need to use DTO in Play Framework before data rendering?

Examples shows rendering of the persistent instances, like this:

http://ift.tt/1Awq5MS

public static index() {
    Query query = JPA.em().createQuery("select * from Article");
    List<Article> articles = query.getResultList();

    render(articles);
}

Do I need to do rendering of the persistence objects or I should use DTO pattern before?

public static index() {
    Query query = JPA.em().createQuery("select * from Article");
    List<ArticlePO> articlesPo = query.getResultList(); // persistence objects...
    List<ArticleVO> articlesVo = new ArrayList<ArticleVO>(); // view objects...

    for(ArticlePO articlePo : articlesPo) {
        ArticleVO articleVo = new ArticleVO();
        articleVo.setPropertyOne(articlePo.getPropertyOne);
        // and so on
        articlesVo.add(articleVo);
    }

    render(articlesVo);
}

I would be very grateful for the information. Thanks to all.

Aucun commentaire:

Enregistrer un commentaire