简体   繁体   English

JpaRepository中的动态实体名称?

[英]Dynamic entity name in JpaRepository?

I'm using spring JpaRepository , and want to provide a generic interface with generic derived SQL queries as follows using el expressions: 我正在使用spring JpaRepository ,并希望使用el表达式提供具有通用派生SQL查询的通用接口,如下所示:

public interface BaseRepo <B> extends CrudRepository<B, Long> {
    @Query("SELECT b FROM #{#entityName} b)
    List<B> findAllB();
}

@Entity
class Booking {} //results in "booking"

This works fine! 这样很好! But what if the desired entity contains an underscore? 但是,如果所需实体包含下划线怎么办? How could I define the strategy of how the el expressions translate the entity name? 我如何定义el表达式如何翻译实体名称的策略?

@Entity
@Table(name = "booking_entity")
class BookingEntity {} //results in "bookingentity", missing underscore!

您可以使用注释@Entity(name="booking_entity")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM