Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何在Hibernate中的Crud Repo中创建where查询函数?_Spring_Spring Boot_Hibernate_Jpa_Spring Data Jpa - Fatal编程技术网

Spring 如何在Hibernate中的Crud Repo中创建where查询函数?

Spring 如何在Hibernate中的Crud Repo中创建where查询函数?,spring,spring-boot,hibernate,jpa,spring-data-jpa,Spring,Spring Boot,Hibernate,Jpa,Spring Data Jpa,我目前正在学习SpringBoot和hibernate 我创建了员工实体和员工回购 @Entity @Table(name = "staffs") public class Staff { private String name; private String gender; private String email; private Integer mobile; private String joined; @Id privat

我目前正在学习SpringBoot和hibernate

我创建了员工实体和员工回购

@Entity
@Table(name = "staffs")
public class Staff {

    private String name;
    private String gender;
    private String email;

    private Integer mobile;

    private String joined;

    @Id
    private String staffID;

    private String password;

    private Integer isAdminStaff;

    private Integer instID;

getters and setter....

}


public interface StaffRepository extends CrudRepository <Staff,String> {
}
@AutoWired
StaffRepository staffRepo

Staff staff= staffRepo.login("john@example.com","aabc123xy",13);// execute above where query

if (staff != null) youLoggedIn();
else wrongCredits();
我需要在staff repo中创建这样的方法

@Entity
@Table(name = "staffs")
public class Staff {

    private String name;
    private String gender;
    private String email;

    private Integer mobile;

    private String joined;

    @Id
    private String staffID;

    private String password;

    private Integer isAdminStaff;

    private Integer instID;

getters and setter....

}


public interface StaffRepository extends CrudRepository <Staff,String> {
}
@AutoWired
StaffRepository staffRepo

Staff staff= staffRepo.login("john@example.com","aabc123xy",13);// execute above where query

if (staff != null) youLoggedIn();
else wrongCredits();
如何实现这一点

此查询的其他帮助::

SELECT enrolled_courses.enrollID,student.name,student.studentid from enrolled_courses INNER JOIN student where enrolled_courses.studentid = student.studentid AND student.instID = 13 AND enrolled_courses.courseid = '13I01C'

您可以这样使用JPA方法命名查询

Staff findByEmailAndPasswordAndInstId(String email, String password, Integer id);
在您的
StaffRepository
中使用它,并使用您的数据调用它

Staff staff= staffRepo.findByEmailAndPasswordAndInstId("john@example.com","aabc123xy",13);

注:根据此标准,假设他们是唯一的员工

请提供一份帮助。。。此查询是否有任何内置方法::从已注册课程中选择已注册课程。注册ID,学生。名称,学生。学生。学生ID=已注册课程中的学生。学生ID=学生。学生ID=学生。学生。学院ID=13,已注册课程。课程ID='13I01C'@LordCommander这是一个完全不同的查询。请张贴另一个问题与使用的实体和他们的关系,以便它将更清楚你的意图。