我无法通过 roo 为一对多关系生成适当的 GUI。特别是,我需要一个多项选择元素来选择与用户相关联的权限(弹簧安全)。
我创建了我的 RegisteredUser 类:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class RegisteredUser extends MyUser implements UserDetails,
CredentialsContainer {
private String password;
private String username;
private Boolean enabled = true;
private Boolean accountNonExpired = true;
private Boolean credentialsNonExpired = true;
private Boolean accountNonLocked = true;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<MyBaseAuthority> authorities = new HashSet<MyBaseAuthority>();
@Override
public void eraseCredentials() {
password = null;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return authorities;
}
@Override
public String getPassword() {
return password;
}
@Override
public String getUsername() {
return username;
}
@Override
public boolean isAccountNonExpired() {
return accountNonExpired;
}
@Override
public boolean isAccountNonLocked() {
return accountNonLocked;
}
@Override
public boolean isCredentialsNonExpired() {
return credentialsNonExpired;
}
@Override
public boolean isEnabled() {
return enabled;
}
}
然后是 MyBaseAuthority 类:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class MyBaseAuthority extends ObjectWithId implements
GrantedAuthority {
private String authority;
@Override
public String getAuthority() {
return authority;
}
}
然后我必须为 MyBaseAuthority 手动创建控制器,但不是为 RegisteredUser(由 webmvc 命令生成):
@RequestMapping("/registeredusers")
@Controller
@RooWebScaffold(path = "registeredusers", formBackingObject = RegisteredUser.class)
public class RegisteredUserController {
}
@RequestMapping("/authorities")
@Controller
@RooWebScaffold(path = "authorities", formBackingObject = MyBaseAuthority.class)
public class MyBaseAuthorityController {
}
在 GUI 上,我可以创建并列出所有权限和注册用户。但是,在创建注册用户时,我只能设置字符串字段和布尔字段,不能设置一对多的关系。我该如何解决?