Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following code:

@Entity
public class StudentEntity {
    @Id
    private String id;
    private Student student;
    ...
}


public class Student {
    private String name;
    private List<Grade> grades;
}


public class Grade {
    private String className;
    private String grade;
}

I've set up a spring data mongodb repository and I'm trying to create a method that will return me a List<Student> based on a className that I pass in as parameter. Based on everything I've read, I assumed that the following would work:

public List<Student> findByStudentGradesClassName(final String className);

but that gives an error saying that the parameter type should be a Grade object. I really only want to pass in a String className.

Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
98 views
Welcome To Ask or Share your Answers For Others

1 Answer

You would have to separate nested fields with underscore:

public List<Student> findByStudent_Grades_ClassName(final String className);

Note, that you still have to start field names with uppercase.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...