我有一個表單設置爲發送POST請求到Grails控制器,該控制器使用命令對象作爲其一個參數。命令對象包含一些正確綁定的屬性以及不能正確綁定的項目列表。我正在做的是通過POST請求正常發送其他參數,但將列表作爲JSON字符串包裝起來,因爲我不確定通過POST發送列表的另一種方式(除了XML字符串之外) 。獲取命令對象從字符串中正確綁定列表的最後一步是什麼,或者有更好的方式將列表發送到命令對象?Grails 2.5.0 - 命令對象使用JSON處理POST請求
編輯: 下面是一個簡化的版本:
測試URI:
request.forwardURI = 'list1=[{"listprop1":"a","listprop2":"b"}]&prop1=c&prop2=d'
的命令對象:
class MyListCommand {
String listprop1
String listprop2
static constraints = {
listprop1 nullable: true
listprop2 nullable: true
}
}
class MyCommand {
List<MyListCommand> list1 = [].withLazyDefault {
new MyListCommand('[]')
}
String prop1
String prop2
static constraints = {
prop1 nullable: true
prop2 nullable: true
}
}
形式:
<form action="${createLink(action: 'myAction')}" method="post">
<div ng-repeat="list1 in list1array">
<input type="hidden" name="list1[{{ $index }}].listprop1" value="{{list1.listprop1}}"/>
<input type="hidden" name="list1[{{ $index }}].listprop2" value="{{list1.listprop2}}"/>
</div>
<input name="prop1" type="text">
<input name="prop2" type="text">
</form>
您需要包含命令對象以及您的表單(或者您如何撰寫您發佈的數據),以便任何人都能就如何解決這個問題給出一個很好的答案。 –
我添加了相關信息。我加入forwardURI(我從Fiddler簡化了)。 – Anonymous1