我的域类被声明为我使用 Grails 1.3.7
StudentReport{
String username
String studentName
}
def sp = StudentReport.createCriteria()
def studentReportList = sp.list {
projections {
property 'username'
property 'studentName'
}
firstResult 0
maxResults 20
order("id", "asc")
}
render studentReportList as JSON
My expected result is
[
{"username":"13B06","student_name":"JOHN SAMUEL"},
{"username":"13B07","student_name":"KATHIRESAN.K"},
{"username":"13B08","student_name":"KATHIRESAN.K"},
{"username":"13B11","student_name":"MALINI.S"}
]
But what i get is
[
["13B06","JOHN SAMUEL"],
["13B07","KATHIRESAN.K"],
["13B08","KATHIRESAN.K"],
["13B11","MALINI.S"]
]
我需要属性名称和花括号。任何人都可以帮助我。我尝试在控制器中不使用投影,然后我得到了确切的结果,但如果我尝试使用投影,那么我坚持得到相同的结果。