我在 grails 应用程序的 src 文件夹下有一个名为 MdNote 的 groovy 类。我引用了另一个类,因为它的属性名为 ReviewOfSystem。在那个类中,我有两个对象。现在,当我绑定(bind) mdNotes 时,如何在 Controller 中绑定(bind)这两个对象属性。我有以下尝试。有人可以帮我吗?
备注 >>
class MdNote {
String ...
String ....
List<ReviewOfSystem> reviewOfSystems
String ....
}
系统评论
class ReviewOfSystem {
String btnLabel
String textValue
}
在 Controller 中 >>
List reviewOfSystems = Arrays.asList(params.reviewOfSystems.split("\\s*~\\s*"));
List<ReviewOfSystem> rosList = null
reviewOfSystems.each {
rosList.btnLabel = 'a'
rosList.textValue = 'b'
}
在 Controller 中,它显示此工具提示::无法将字符串分配给 arraylist。
任何人都可以帮我分配这些值。
最佳答案
我得到了答案。
List reviewOfSystems = Arrays.asList(params.reviewOfSystems.split("\\s*~\\s*"));
ArrayList<ReviewOfSystem> ros= new ArrayList<ReviewOfSystem>();
reviewOfSystems.each {
String idxValue = it
ReviewOfSystem reviewOfSystem = new ReviewOfSystem();
reviewOfSystem.btnLabel = idxValue.substring(0, idxValue.lastIndexOf("^"))
reviewOfSystem.textValue = idxValue.substring(idxValue.lastIndexOf("^") + 1)
ros.add(reviewOfSystem);
}
关于grails - 如何在grails的groovy类列表中添加两个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050814/