0
grails的重定向方法只能接受一個域類來重定向到相應的'show'視圖。爲什麼方法redirect()只接受grails 2.5.x的一個參數
book.save flush:true
withFormat {
html {
flash.message = message(code: 'default.created.message', args: [message(code: 'book.label', default: 'Book'), book.id])
redirect book
}
'*' { render status: CREATED }
}
但源代碼
public Object redirect(Object instance,Object object) {
if(object != null) {
Class<?> objectClass = object.getClass();
boolean isDomain = DomainClassArtefactHandler.isDomainClass(objectClass) && object instanceof GroovyObject;
if(isDomain) {
Object id = ((GroovyObject)object).getProperty(GrailsDomainClassProperty.IDENTITY);
if(id != null) {
Map args = new HashMap();
args.put(LinkGenerator.ATTRIBUTE_RESOURCE, object);
args.put(LinkGenerator.ATTRIBUTE_METHOD, HttpMethod.GET.toString());
return redirect(instance, args);
}
}
}
throw new CannotRedirectException("Cannot redirect for object ["+object+"] it is not a domain or has no identifier. Use an explicit redirect instead ");
}
表明,2個參數都應該被傳遞給該方法。其實我只能將第二個參數傳遞給方法。爲什麼?