Playframework-查询和显示多表联接的结果 [英] Playframework - querying and displaying results from multi-table join

查看:86
本文介绍了Playframework-查询和显示多表联接的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java和play框架的新手(我在本地MySQL5数据库中使用play 1.2.2).我正在尝试查询数据库中的几个表,并将表联接结果显示在网页上.

I'm a newcomer to java and the play framework (I'm using play 1.2.2 with a local MySQL5 database). I'm trying to query a couple of tables in a database and display the table join results on a web page.

这是我在各个方面所拥有的:

This is what I have in the various bits:

控制器:-

public static void index() {
        List<Mutation> mutation_list= Mutation.getDisorderGene();
        render(mutation_list);       
    }

模型:-

public class Mutation extends Model {

  public static List<Mutation> getDisorderGene() {
    EntityManager entityManager = play.db.jpa.JPA.em();
    List<Mutation> muts = entityManager.createNativeQuery("select disorder_name, gene_name from Disorder,Mutation where Disorder.id = Mutation.disorder_id order by disorder_name, gene_name").getResultList();
    return muts;
  }

查看:-

#{list items:mutation_list, as:'mutation'}
                    <tr>
                        <td>${mutation.disorder_name}</td>
                        <td>${mutation.gene_name}</td>
                    </tr>
 #{/list}            

这是我收到的错误消息!

And this is the error message I get!

模板执行错误

Template execution error

执行错误发生在模板/app/views/Stu/index.html中. 引发的异常为MissingPropertyException:异常评估 java.util.Arrays $ ArrayList的属性'disorder_name',原因: groovy.lang.MissingPropertyException:没有这样的属性:disorder_name 用于课程:java.lang.String.

Execution error occured in template /app/views/Stu/index.html. Exception raised was MissingPropertyException : Exception evaluating property 'disorder_name' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: disorder_name for class: java.lang.String.

我不确定问题出在哪里.是JPA表联接查询,还是视图中有问题.

I'm unsure where the problem lies. Is it with the JPA table join query or is something wrong in the view.

我可以在显示列的视图中进行任何更改吗?

Are there any changes in the view I can make to display the columns?

非常感谢.

推荐答案

默认情况下选择多个列的本机查询将其返回为Object[],因此您的getDisorderGene()应该返回一个List<Object[]>,并且您的模板应该看起来像如下:

A native query that selects multiple columns by default returns them as Object[], thus your getDisorderGene() should return a List<Object[]>, and your template should look as follows:

#{list items:mutation_list, as:'mutation'}
                    <tr>
                        <td>${mutation[0]}</td>
                        <td>${mutation[1]}</td>
                    </tr>
 #{/list}  

这篇关于Playframework-查询和显示多表联接的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆