使用MongoDB CustomRepository和嵌套数据访问的Spring Boot

时间:2019-12-16 21:11:04

标签: mongodb spring-boot mongodb-query spring-data spring-data-mongodb

我正在尝试通过创建User接口从WorkDateCustomUserWorkdateRepository存储库中构建CustomRepository。我明确只想从WorkTime访问用户特定的WorkDate。因此,我想创建一个查询,在其中为WorkDate的属性yearmonthday指定一个属性,并仅返回WorkTime对象(例如Graphql )。那有可能吗?那么CustomUserWorkDateRepository会是什么样子?

public interface CustomUserWorkdateRepository extends MongoRepository<User, String> {
    ...?
}

public interface WorkDateRepository extends MongoRepository<WorkDate, Integer> {
    public List<WorkDate> findByYear(User user, Integer year);
    public List<WorkDate> findByYearAndMonth(User user, Integer year, Integer month);
}

public class WorkDate {
    public int year;
    public int month;
    public int day;
    public WorkTime workTime;
}

public class WorkTime {
    public Date startTime;
    public Date endTime;
    public Date workTime;
    public Date pauseTime;
}

public interface UserRepository extends MongoRepository<User, String> {
    public User findByFirstName(String firstName);
    public List<User> findByLastName(String lastName);
}

public class User {
    @Id
    public String id;
    public String firstName;
    public String lastName;
...

}

0 个答案:

没有答案