我正在使用 spring JpaRepository
,并且希望使用 el
表达式提供具有通用派生 SQL 查询的通用接口(interface),如下所示:
public interface BaseRepo <B> extends CrudRepository<B, Long> {
@Query("SELECT b FROM #{#entityName} b)
List<B> findAllB();
}
@Entity
class Booking {} //results in "booking"
这很好用!但是如果所需的实体包含下划线怎么办?如何定义 el 表达式翻译实体名称的策略?
@Entity
@Table(name = "booking_entity")
class BookingEntity {} //results in "bookingentity", missing underscore!
最佳答案
您可以使用注释@Entity(name="booking_entity")
。
关于java - JpaRepository 中的动态实体名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29410625/