播放框架和ebean从只读数据库中获取表数据作为Json

时间:2018-12-19 16:15:14

标签: java json playframework model ebean

所以我试图从一个远程只读oracle db 视图获取表数据作为json。我的实体看起来像这样:

Test.java

var results = {
   "tab":[
      "[[\"2018\",11,\"19\",\"16\",\"13\"],null,null,null,null,null,\"40\"]",
      "[[\"2018\",11,\"19\",\"16\",\"19\"],null,null,null,null,null,\"56\"]",
      "[[\"2018\",11,\"19\",\"16\",\"21\"],null,null,null,null,\"57\",null]"
   ]
};

// you can refactor this as a method for more convenient usage, this is just a demo
var row = JSON.parse(results.tab[0]);

// now you just have a multi-dimensional array, use it as normal
console.log(row[0][0]); //year
console.log(row[6]); //number

SubTest.java

@Entity
@Table(schema = "`myschema`", name = "mytable")
public class Test extends Model {

@Column
public String description;

@Column
public String enginenum;

public List<SubTest> subtest;

public static final Finder<String, Test> find = new Finder<>(Test.class, "mydbname");

MyController.java

@Entity
@Table(schema = "`myschema`", name = "mytable")
public class SubTest extends Model {

@Column
public String site;

@Column
public String unitnum;

public Test test;

我能够从Test模型获取描述和enginenum到我的json数组,但是List将返回为空。我应该映射这些模型之间的关系吗?一个只读视图甚至有可能吗?

0 个答案:

没有答案