以域类User
和Role
为例:
@Resource(uri='/api/user', formats=['json', 'xml'])
class User {
String username
String password
static hasMany = [roles: Role]
}
@Resource(uri='/api/role', formats=['json', 'xml'])
class Role {
String authority
static hasMany = [users: User]
static belongsTo = [User]
}
/api/user
和/api/user/1
都会获取关联的Role
个对象。如何使/api/user
仅返回获取相关User
个对象的Role
个对象WIHTOUT列表,而/api/user/1
将返回User
个id=1
个对象}和关联的Role
对象?
答案 0 :(得分:0)
您可以通过...编写自己的实现来完成此操作。 Grails的@Resource
实现不支持您正在寻找的这些非常具体的功能。实现您自己的管理fetchMode
的控制器,以满足您自己的需求。