使用单个实体类和一个通用mongo存储库的相同结构的两个不同的Spring mongo集合

时间:2019-06-27 11:32:32

标签: mongodb inheritance

嗨,我需要添加两个mongo存储库才能使其工作吗?或一个通用的仓库可以创建两个收藏夹?

`公共接口EmployeeRepository扩展了MongoRepository {         {

    }

    manager
    {
    id:"abc",
    name:”PP”,
    age:26
    }

    supervisor
    {
    id:"abc",
    name:"Raj",
    age:25
    }
    public  class Employee
    {
      private String id;
      private String name;
      private int age;
    }
    @Document(collection="manager")
    public class Manager extends Employee
    {
    }
    @Document(collection="supervisor")
    public class Supervisor extends Employee
    {
    }
    public interface EmployeeService<T> 
    {
        public T save(T employee);
    }
    @Service
    public class EmployeeServiceImpl<T> implements EmployeeService<T> 
    {
        @Autowired
        EmployeeRepository employeeRepository;
@Override
        public T save(T obj) {
            return (T) employeeRepository.save(obj);
        }
}

`

0 个答案:

没有答案