spring-data-mongodb - @Document(collection = "collectionName") 扩展另一个类时不起作用
问题描述
我正在使用 spring data mongoDB 开发一个 spring boot 应用程序。我有一个包含所有公共属性的公共类,我的其他类扩展了它,以便我在其中拥有这些公共属性。
@Getter
@Setter
@EntityListeners({AuditingEntityListener.class})
public abstract class AbstractAuditEntity implements Serializable {
@CreatedBy
@NotNull
private Long createdBy;
@LastModifiedBy
@NotNull
private Long updatedBy;
@CreatedDate
@NotNull
private Instant createdDate;
@LastModifiedDate
@NotNull
private Instant updatedDate;
}
现在当我在我的另一个类中扩展这个类时
@Document(collection = "consumer")
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ConsumerEntity extends AbstractAuditEntity {
@Id
private ObjectId id;
}
在 mongo 数据库中创建的文档与我的类名相同,即“ConsumerEntity”,我如何让 @Document(collection = "consumer") 工作,以便在我的 mongo 数据库中将集合名称反映为“consumer”。谢谢你
解决方案
推荐阅读
- angular - 如何以角度单独添加用户和管理员导航
- python - 在参数化函数中仅使用一次夹具
- cmake - cmake transitive usage: propagate libs but keep headers private
- java - 更改地图类型时,mapbox.getStyle() 返回 null
- android - 如何通过其他活动填写多领域活动?
- python - 管道文件中存在问题,因为它没有获取书名。而是为每次爬网保存一个带有 None.jpg 的随机图像
- javascript - 从javascript代码中读取类属性
- typescript - 打字稿在编译时找不到模块
- react-table - 如何将自定义道具从 App 传递到单元格以进行 react-table v7?
- hadoop - putHDFS 处理器中的 Nifi 错误:无法确定当前用户