1
在我的項目中,我試圖從請求的參數中返回選定的元素作爲JSON。Grails - 從請求參數返回選定的json元素
域類:
class Component{
String name
String level
.
.
.
}
我有HTTP請求像
http://localhost:8080/myapp/component/showJson?name=name
所以我應該只返回
{
name:xyz
}
如果我的要求是一樣
http://localhost:8080/myapp/component/showJson?name=name&level=level
然後我應該回到
{
name:xyz
level:1
}
任何建議表示讚賞。
更新JSON(多級)
[
{"name":"one","level":0,"
componentTypes":[
{"name":"one one","level":1,
"componentTypes":[
{"name":"one one one","level":2,"componentTypes":[]}
]
},
{"name":"one two","level":1,"componentTypes":[]}
]
},
{"name":"two","level":0,"componentTypes"[]},
{"name":"three","level":0,"componentTypes":[]}
]
class ComponentType {
String name
Integer level
static hasMany = [componentTypes:ComponentType]
ComponentType parent
static constraints = {
parent nullable:true
}
static mapWith = "mongo"
}
控制器動作
componentTypeList = ComponentType.createCriteria().list(){
eq("level", 0)
}
如果我們有組件(產品清單),那麼如何進行 –
的產品清單更新的答案。 – JChap
我面對的問題是,多層次,組件有很多組件 –