Grails中render obj as JSON时出现的问题:obj中有一个属性为另一个实体类对象,为什么不能把它转换完全? 20
实体类:classSuperHello{Stringsexintage}classHello{StringnamedoubleweightdoubleheightSupe...
实体类:
class SuperHello {
String sex
int age
}
class Hello {
String name
double weight
double height
SuperHello sp
}
转换代码:
Hello p = new Hello(name:"luobo")
SuperHello spp = new SuperHello()
spp.id = 2
spp.sex = "man"
p.sp = = new SuperHello()
render p as JSON
运行结果:
{"class":"hellotest.Hello","id":null,"height":0,"name":"luobo","sp":{"class":"SuperHello","id":2},"weight":0} 展开
class SuperHello {
String sex
int age
}
class Hello {
String name
double weight
double height
SuperHello sp
}
转换代码:
Hello p = new Hello(name:"luobo")
SuperHello spp = new SuperHello()
spp.id = 2
spp.sex = "man"
p.sp = = new SuperHello()
render p as JSON
运行结果:
{"class":"hellotest.Hello","id":null,"height":0,"name":"luobo","sp":{"class":"SuperHello","id":2},"weight":0} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询