我正在尝试通过创建User
接口从WorkDate
和CustomUserWorkdateRepository
存储库中构建CustomRepository。我明确只想从WorkTime
访问用户特定的WorkDate
。因此,我想创建一个查询,在其中为WorkDate
的属性year
,month
,day
指定一个属性,并仅返回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;
...
}