Spring boot 使用findAll()方法时,Spring Boot JPARepository未显示id
我正在创建一个Spring启动应用程序,但是我的findAll(使用JPARepository实现)返回除id之外的所有属性,我需要尝试创建的视图的id。有没有办法改变这一点?我现在有 /model/rol.javaSpring boot 使用findAll()方法时,Spring Boot JPARepository未显示id,spring-boot,jpa,Spring Boot,Jpa,我正在创建一个Spring启动应用程序,但是我的findAll(使用JPARepository实现)返回除id之外的所有属性,我需要尝试创建的视图的id。有没有办法改变这一点?我现在有 /model/rol.java @Entity @Table(name = "roles") public class rol { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column(name = "r
@Entity
@Table(name = "roles")
public class rol {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "rol", nullable = false)
private String rol;
@OneToMany(mappedBy = "rol", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<Administrador> administradores;
public rol() {
}
public rol(String rol) {
this.rol = rol;
}
/* Getters and Setters */
/templates/roles.html
<table class="table table-striped">
<thead class="thead-dark" >
<tr>
<th scope="col"> ID </th>
<th scope="col"> Rol </th>
</tr>
</thead>
<tbody>
<tr th:if="${roles.empty}">
<td colspan="2"> No hay roles registrados </td>
</tr>
<tr th:each="rol : ${roles}">
<td><span th:text="${rol.id}"> Rol </span></td>
<td><span th:text="${rol.rol}"> Rol </span></td>
</tr>
</tbody>
</table>
身份证件
罗尔
没有干草
罗尔
罗尔
但是,我在计算SpringEL表达式时得到错误异常:“rol.id”
经过一些研究,我发现JPARepository显然没有在findAll()
方法中包含模型的id
有没有办法修改findAll()
或任何其他文件,以便能够使用我的HTML表中的id
提前谢谢
预期的输出是我的表中的rol.id值,但是,实际结果是计算SpringEL表达式时出现异常:“rol.id”@Repository
公共接口rolrepository扩展了JpaRepository{
}
JpaRepository arg
JpaRepository<rol, Long>
JpaRepository
指示ID的类型为Long,但您在rol java代码中使用的是int ID
尝试在rol.java@存储库中使用长id
公共接口rolrepository扩展了JpaRepository{
}
JpaRepository arg
JpaRepository<rol, Long>
JpaRepository
指示ID的类型为Long,但您在rol java代码中使用的是int ID
尝试在rol.java中使用长id。首先,rol不是正确的类名。您应该开始练习命名约定 第二件事,当您使用jparepository/crudepository时,请确保您在POJO类中获取的id列的数据类型与存储库中的id列的数据类型相同。 参考这个
@Repository
public interface rolrepository extends JpaRepository<Rol, Long>{
}
@存储库
公共接口rolrepository扩展了JpaRepository{
}
首先,rol不是正确的类名。你应该开始练习命名约定
第二件事,当您使用jparepository/crudepository时,请确保您在POJO类中获取的id列的数据类型与存储库中的id列的数据类型相同。
参考这个
@Repository
public interface rolrepository extends JpaRepository<Rol, Long>{
}
@存储库
公共接口rolrepository扩展了JpaRepository{
}
您是否尝试过为id字段添加一个getter并通过getter访问id?JPA没有包含id的说法是错误的。您在哪里发现了这种错误信息?你能包含整个堆栈跟踪吗?你的ID在POJO中是int类型的,但在REPO中你通过了LONG…aka…也改进了命名约定。。。。rol should rol..etchave您是否尝试为id字段添加一个getter并通过getter访问id?JPA不包含id的说法是错误的。您在哪里发现此错误信息?你能包含整个堆栈跟踪吗?你的ID在POJO中是int类型的,但在REPO中你通过了LONG…aka…也改进了命名约定。。。。rol应该rol…等等
@Repository
public interface rolrepository extends JpaRepository<Rol, Long>{
}