JPA - Java Spring Boot - doing a look up/joining t

2020-08-02 20:10发布

问题:

I am new to Java Spring Boot and JPA. I've got two tables -- one is an accounts table the site will manage "TblLogin" - the other "TblPatient" will be populated by third-party data (unmanaged) on the site.

//look up method

  1. So in this demo here - I have a user login -- email, password -- I need to do first a look up that satisfies not just "findByEmail" - but also "findByEmailAndPassword" and also encrpt the password value before it goes off to do a check.

  2. On finding an acc -- it then gets the pin col data - like 1345 -- and does a look up on the third party table. --

-- now I am sure there is a more sophisticated way of doing this - maybe even via a join? But I am unsure.

            TblLogin acc = tblLoginRepository.findByEmail(email);   

            String pin = acc.getPin();
            TblPatient ext = tblPatientRepository.findByPatientID(pin);

            JSONObject response = new JSONObject();
                response.put("tblLogin", acc.getEmail());
                response.put("tblPatient", ext.getId());                    
  1. would it be something like Would it be something like -- "findByEmailContainingAndPasswordContainingAllIgnoringCase(String email, String passwordEncoder.encode(password));" ?

or more like

findByEmailAndPasswordAllIgnoringCase(String email, String passwordEncoder.encode(password)));