通过长堆栈转储,Grails可能有点像熊一样调试.找到问题的根源可能很棘手.我在BootStrap.groovy中做过几次烧伤,例如"def foo = new Foo(a:a,b:b).save()".您最喜欢调试Grails应用程序的技巧是什么?
Grails 非常支持将请求参数绑定到域对象及其关联.这在很大程度上依赖于检测.id以数据库结束并自动加载数据库的请求参数.
但是,目前尚不清楚如何填充命令对象的关联.请看以下示例:
class ProductCommand {
String name
Collection<AttributeTypeCommand> attributeTypes
ProductTypeCommand productType
}
Run Code Online (Sandbox Code Playgroud)
该对象具有单端关联ProductTypeCommand和多端关联AttributeTypeCommand.所有属性类型和产品类型的列表都可从此接口的实现中获得
interface ProductAdminService {
Collection<AttributeTypeCommand> listAttributeTypes();
Collection<ProductTypeCommand> getProductTypes();
}
Run Code Online (Sandbox Code Playgroud)
我使用此界面填充GSP中的产品和属性类型选择列表.我还依赖 - 将此接口注入命令对象,并使用它来"模拟" 命令对象attributeTypes和productType属性
class ProductCommand {
ProductAdminService productAdminService
String name
List<Integer> attributeTypeIds = []
Integer productTypeId
void setProductType(ProductTypeCommand productType) {
this.productTypeId = productType.id
}
ProductTypeCommand getProductType() {
productAdminService.productTypes.find {it.id == productTypeId}
}
Collection<AttributeTypeCommand> getAttributeTypes() {
attributeTypeIds.collect {id ->
productAdminService.getAttributeType(id)
}
}
void setAttributeTypes(Collection<AttributeTypeCommand> attributeTypes) {
this.attributeTypeIds …Run Code Online (Sandbox Code Playgroud)