【问题标题】:No converter found capable of converting没有找到能够转换的转换器
【发布时间】:2021-02-21 17:08:18
【问题描述】:

我正在使用 Spring Boot 开发一个应用程序,我在其中实现身份验证和授权。这是我的角色实体

@Entity
public class Role extends BaseModel {

    private String name;
    private Set<User> users;
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }
}

Rold id 在 BaseModel 中。我想从 db 中获取所有角色,为此我在 RoleRepository 中编写了这样的方法

@Query("select r.id,r.name from Role r")
List<Role> getAllRoles();

但它让我重新收到这个错误

org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型 [java.lang.Integer] 转换为类型 [@org.springframework.data.jpa.repository.Query com.example.demo.model 的转换器.角色]

感谢您的帮助。

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    尝试将角色存储库中的方法更改为:

    @Query("select r from Role r")
    List<Role> getAllRoles();
    

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 1970-01-01
      • 2018-02-15
      • 2020-11-19
      • 1970-01-01
      • 2021-11-19
      • 2019-10-20
      • 2019-02-10
      • 2021-09-22
      相关资源
      最近更新 更多