我正在尝试构建一个 Play!针对现有数据库运行的应用程序,其中所有列都有下划线来分隔单词。这意味着我必须在每个字段上放置一个 @Column
注释以指定不同的名称。有没有办法得到 Play!默认使用下划线?
最佳答案
如果 Play 使用 Hibernate,正如其他答案所建议的那样,您将不得不 implement a custom NamingStrategy
。
下面是一个 NamingStrategy 示例,它使用 Guava 将所有列名从小驼峰转换为带下划线的小写:
public class CustomNamingStrategy extends ImprovedNamingStrategy {
private static final long serialVersionUID = -306957679456120781L;
@Override
public String columnName(final String columnName) {
return CaseFormat.LOWER_CAMEL
.to(CaseFormat.LOWER_UNDERSCORE, columnName);
}
}
这样配置:
add the following line to application.conf to configure the NamingStrategy
hibernate.ejb.naming_strategy=<your naming strategy classname>
引用:
关于java - 有没有办法让 Play 框架和 JPA 在列名中使用下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5796683/