【发布时间】:2016-06-21 04:55:49
【问题描述】:
mongodb是一个无模式的文档数据库,但是在spring data中,需要定义实体类和repository类,如下:
实体类:
@Document(collection = "users")
public class User implements UserDetails {
@Id private String userId;
@NotNull @Indexed(unique = true) private String username;
@NotNull private String password;
@NotNull private String name;
@NotNull private String email;
}
存储库类:
public interface UserRepository extends MongoRepository<User, String> {
User findByUsername(String username);
}
有没有办法在 spring data mongodb 中使用 map not class,以便服务器可以接受任何动态 JSON 数据,然后将其存储在 BSON 中而无需任何前类定义?
【问题讨论】: