Spring mvc 在thymeleaf中显示内部对象
我正在尝试在应用程序中显示我的用户角色 这是我的豆子Spring mvc 在thymeleaf中显示内部对象,spring-mvc,spring-boot,spring-data-jpa,thymeleaf,Spring Mvc,Spring Boot,Spring Data Jpa,Thymeleaf,我正在尝试在应用程序中显示我的用户角色 这是我的豆子 private Set<ClientRole> clientRoles = new HashSet<>(); } 这里是角色实体。Bean正在尝试访问这些角色 百里香。因为我正在使用thymeleaf extras spring security 4。我会的 像管理员一样,用户可以修改角色。我希望能够 显示和修改。其他字段正确显示,但 clientRolse给了我一根长长的绳子。 com.zenopoint.doma
private Set<ClientRole> clientRoles = new HashSet<>();
}
这里是角色实体。Bean正在尝试访问这些角色
百里香。因为我正在使用thymeleaf extras spring security 4。我会的
像管理员一样,用户可以修改角色。我希望能够
显示和修改。其他字段正确显示,但
clientRolse给了我一根长长的绳子。
com.zenopoint.domain.Client.clientRoles
@Entity
public class Role {
@Id
private int roleId;
private String name;
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL, fetch =
FetchType.LAZY)
private Set<ClientRole> clientRoles = new HashSet<>();
public Role() {
}
public int getRoleId() {
return roleId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<ClientRole> getClientRoles() {
return clientRoles;
}
public void setClientRoles(Set<ClientRole> clientRoles) {
this.clientRoles = clientRoles;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
@实体
公共阶级角色{
@身份证
私人内部控制;
私有字符串名称;
@OneToMany(mappedBy=“role”,cascade=CascadeType.ALL,fetch=
FetchType.LAZY)
private Set clientRoles=new HashSet();
公共角色(){
}
public int getRoleId(){
返回roleId;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共集getClientRoles(){
返回客户端角色;
}
public void setClientRoles(Set clientRoles){
this.clientRoles=clientRoles;
}
公共void setRoleId(int-roleId){
this.roleId=roleId;
}
}
这是我的控制器
@RequestMapping("/accounts")
public String accounts(Model model) {
List<Client> clientsList = userservice.findUserList();
model.addAttribute("clientsList", clientsList);
return "app/accounts";
}
@RequestMapping(“/accounts”)
公共字符串帐户(模型){
List clientsList=userservice.findUserList();
addAttribute(“clientsList”,clientsList);
返回“应用程序/帐户”;
}
这是我的用户服务
public List<Client> findUserList() {
return clientDao.findAll();
}
public interface ClientDao extends CrudRepository<Client , Long> {
Client findByPhone(String phone);
Client findByEmailaddress(String emailaddress);
Client findByUsername(String username);
List<Client> findAll();
}
@Entity
public class Client implements UserDetails{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long client_id;
@Column(unique = true, nullable = false)
@NotEmpty
private String username;
@NotEmpty
private String password;
@Email
@Column(nullable = false, unique = true)
private String emailaddress;
@NotEmpty
private String companyname;
@Column(nullable = false)
private String companyurl;
@NotEmpty
private String street;
@NotEmpty
private String city;
@NotEmpty
private String region;
private String zip;
@Temporal(TemporalType.DATE)
private Date dob;
@Temporal(TemporalType.TIMESTAMP)
private Date doj = new Date();
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
private String nationality;
@Column(unique = true, nullable = false)
@NotEmpty
private String phone;
@NotEmpty
private String position;
private boolean enabled = true;
private String registrationnumber;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "client", cascade = CascadeType.ALL)
private List<Transactions> transactions;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "client", cascade = CascadeType.ALL)
private List<Tokenization> tokenization;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonIgnore
private Set<ClientRole> clientRoles = new HashSet<>();
public Client() {}
public Long getClient_id() {
return client_id;
}
public void setClient_id(Long client_id) {
this.client_id = client_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailaddress() {
return emailaddress;
}
public void setEmailaddress(String emailaddress) {
this.emailaddress = emailaddress;
}
public String getCompanyname() {
return companyname;
}
public void setCompanyname(String companyname) {
this.companyname = companyname;
}
public String getCompanyurl() {
return companyurl;
}
public void setCompanyurl(String companyurl) {
this.companyurl = companyurl;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public Date getDoj() {
return doj;
}
public void setDoj(Date doj) {
this.doj = doj;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getNationality() {
return nationality;
}
public void setNationality(String nationality) {
this.nationality = nationality;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRegistrationnumber() {
return registrationnumber;
}
public void setRegistrationnumber(String registrationnumber) {
this.registrationnumber = registrationnumber;
}
public List<Transactions> getTransactions() {
return transactions;
}
public void setTransactions(List<Transactions> transactions) {
this.transactions = transactions;
}
public List<Tokenization> getTokenization() {
return tokenization;
}
public void setTokenization(List<Tokenization> tokenization) {
this.tokenization = tokenization;
}
public Set<ClientRole> getClientRoles() {
return clientRoles;
}
public void setClientRoles(Set<ClientRole> clientRoles) {
this.clientRoles = clientRoles;
}
@Override
public String toString() {
return "Client [client_id=" + client_id + ", username=" + username + ", password=" + password
+ ", emailaddress=" + emailaddress + ", companyname=" + companyname + ", companyurl=" + companyurl
+ ", street=" + street + ", city=" + city + ", region=" + region + ", zip=" + zip + ", dob=" + dob
+ ", doj=" + doj + ", firstname=" + firstname + ", lastname=" + lastname + ", nationality="
+ nationality + ", phone=" + phone + ", position=" + position + ", enabled=" + enabled
+ ", registrationnumber=" + registrationnumber + ", transactions=" + transactions + ", tokenization="
+ tokenization + ", clientRoles=" + clientRoles + "]";
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Set<GrantedAuthority> authorities = new HashSet<>();
clientRoles.forEach(ur -> authorities.add(new Authority(ur.getRole().getName())));
return authorities;
}
@Override
public boolean isAccountNonExpired() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isAccountNonLocked() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isCredentialsNonExpired() {
// TODO Auto-generated method stub
return true;
}
}
公共列表findUserList(){
返回clientDao.findAll();
}
公共接口ClientDao扩展了crudepository{
客户端findByPhone(字符串电话);
客户端findByEmailaddress(字符串emailaddress);
客户端findByUsername(字符串用户名);
列出findAll();
}
@实体
公共类客户端实现UserDetails{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
专用长客户端id;
@列(unique=true,nullable=false)
@空空如也
私有字符串用户名;
@空空如也
私有字符串密码;
@电子邮件
@列(nullable=false,unique=true)
私有字符串电子邮件地址;
@空空如也
私有字符串companyname;
@列(nullable=false)
私人字符串公司;
@空空如也
私家弦街;;
@空空如也
私人城市;
@空空如也
私有字符串区域;
私人字符串拉链;
@时态(TemporalType.DATE)
私人约会日期;
@时态(TemporalType.TIMESTAMP)
私人日期doj=新日期();
@空空如也
私有字符串名;
@空空如也
私有字符串lastname;
私人国籍;
@列(unique=true,nullable=false)
@空空如也
私人电话;
@空空如也
私有字符串位置;
私有布尔启用=真;
私有字符串注册号;
@OneToMany(fetch=FetchType.LAZY,mappedBy=“client”,cascade=CascadeType.ALL)
私人清单交易;
@OneToMany(fetch=FetchType.LAZY,mappedBy=“client”,cascade=CascadeType.ALL)
私有列表标记化;
@OneToMany(mappedBy=“client”,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@杰索尼奥雷
private Set clientRoles=new HashSet();
公共客户端(){}
公共长getClient_id(){
返回客户端id;
}
公共无效设置客户端id(长客户端id){
this.client\u id=client\u id;
}
公共字符串getUsername(){
返回用户名;
}
public void setUsername(字符串用户名){
this.username=用户名;
}
公共字符串getPassword(){
返回密码;
}
public void setPassword(字符串密码){
this.password=密码;
}
公共字符串getEmailaddress(){
返回电子邮件地址;
}
public void setEmailaddress(字符串emailaddress){
this.emailaddress=电子邮件地址;
}
公共字符串getCompanyname(){
返回公司名称;
}
public void setCompanyname(字符串companyname){
this.companyname=companyname;
}
公共字符串getCompanyurl(){
返回公司URL;
}
public void setCompanyurl(字符串companyurl){
this.companyurl=companyurl;
}
公共字符串getStreet(){
返回街;;
}
公共街道(字符串街){
这条街;
}
公共字符串getCity(){
回归城市;
}
公共城市(字符串城市){
this.city=城市;
}
公共字符串getRegion(){
返回区;
}
公共无效集合区域(字符串区域){
这个区域=区域;
}
公共字符串getZip(){
返回拉链;
}
公共void setZip(字符串zip){
this.zip=zip;
}
公开日期getDob(){
返回dob;
}
公共无效设置日期(日期日期){
this.dob=dob;
}
公开日期getDoj(){
返回司法部;
}
公共无效设定日(日期日){
this.doj=doj;
}
公共字符串getFirstname(){
返回名字;
}
public void setFirstname(字符串firstname){
this.firstname=firstname;
}
公共字符串getLastname(){
返回姓氏;
}
public void setLastname(字符串lastname){
this.lastname=lastname;
}
公共字符串getNational(){
返回国籍;
}
公共国籍(字符串国籍){
国籍=国籍;
}
公共字符串getPhone(){
回电话;
}
公用无效设置电话(字符串电话){
this.phone=电话;
}
公共字符串getPosition(){
返回位置;
}
公共无效设置位置(字符串位置){
这个位置=位置;
}
公共布尔值isEnabled(){
返回启用;
}
已启用公共void集(已启用布尔值){
this.enabled=已启用;
}
公共字符串getRegistrationnumber(){
返回注册号;
}
public void setRegistrationnumber(字符串registrationnumber){
this.registrationnumber=注册号;
}
公共列表getTransa
@RequestMapping("/accounts")
public String accounts(Model model) {
List<Client> clientsList = userservice.findUserList();
model.addAttribute("clientsList", clientsList);
return "app/accounts";
}
public List<Client> findUserList() {
return clientDao.findAll();
}
public interface ClientDao extends CrudRepository<Client , Long> {
Client findByPhone(String phone);
Client findByEmailaddress(String emailaddress);
Client findByUsername(String username);
List<Client> findAll();
}
@Entity
public class Client implements UserDetails{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long client_id;
@Column(unique = true, nullable = false)
@NotEmpty
private String username;
@NotEmpty
private String password;
@Email
@Column(nullable = false, unique = true)
private String emailaddress;
@NotEmpty
private String companyname;
@Column(nullable = false)
private String companyurl;
@NotEmpty
private String street;
@NotEmpty
private String city;
@NotEmpty
private String region;
private String zip;
@Temporal(TemporalType.DATE)
private Date dob;
@Temporal(TemporalType.TIMESTAMP)
private Date doj = new Date();
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
private String nationality;
@Column(unique = true, nullable = false)
@NotEmpty
private String phone;
@NotEmpty
private String position;
private boolean enabled = true;
private String registrationnumber;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "client", cascade = CascadeType.ALL)
private List<Transactions> transactions;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "client", cascade = CascadeType.ALL)
private List<Tokenization> tokenization;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonIgnore
private Set<ClientRole> clientRoles = new HashSet<>();
public Client() {}
public Long getClient_id() {
return client_id;
}
public void setClient_id(Long client_id) {
this.client_id = client_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailaddress() {
return emailaddress;
}
public void setEmailaddress(String emailaddress) {
this.emailaddress = emailaddress;
}
public String getCompanyname() {
return companyname;
}
public void setCompanyname(String companyname) {
this.companyname = companyname;
}
public String getCompanyurl() {
return companyurl;
}
public void setCompanyurl(String companyurl) {
this.companyurl = companyurl;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public Date getDoj() {
return doj;
}
public void setDoj(Date doj) {
this.doj = doj;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getNationality() {
return nationality;
}
public void setNationality(String nationality) {
this.nationality = nationality;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRegistrationnumber() {
return registrationnumber;
}
public void setRegistrationnumber(String registrationnumber) {
this.registrationnumber = registrationnumber;
}
public List<Transactions> getTransactions() {
return transactions;
}
public void setTransactions(List<Transactions> transactions) {
this.transactions = transactions;
}
public List<Tokenization> getTokenization() {
return tokenization;
}
public void setTokenization(List<Tokenization> tokenization) {
this.tokenization = tokenization;
}
public Set<ClientRole> getClientRoles() {
return clientRoles;
}
public void setClientRoles(Set<ClientRole> clientRoles) {
this.clientRoles = clientRoles;
}
@Override
public String toString() {
return "Client [client_id=" + client_id + ", username=" + username + ", password=" + password
+ ", emailaddress=" + emailaddress + ", companyname=" + companyname + ", companyurl=" + companyurl
+ ", street=" + street + ", city=" + city + ", region=" + region + ", zip=" + zip + ", dob=" + dob
+ ", doj=" + doj + ", firstname=" + firstname + ", lastname=" + lastname + ", nationality="
+ nationality + ", phone=" + phone + ", position=" + position + ", enabled=" + enabled
+ ", registrationnumber=" + registrationnumber + ", transactions=" + transactions + ", tokenization="
+ tokenization + ", clientRoles=" + clientRoles + "]";
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Set<GrantedAuthority> authorities = new HashSet<>();
clientRoles.forEach(ur -> authorities.add(new Authority(ur.getRole().getName())));
return authorities;
}
@Override
public boolean isAccountNonExpired() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isAccountNonLocked() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isCredentialsNonExpired() {
// TODO Auto-generated method stub
return true;
}
}
<td th:text="${clients.clientRoles?.role.name}">...</td>
<td data-th-text="${clients.clientRoles}">...</td>
<td>
<tr th:each="a: ${clients.clientRoles}">
<td data-th-text="${a.role.name}">...</td>
</tr>
</td>