检索自动构建查询的spring JPA的所有可能支持的操作的列表

时间:2016-11-16 23:11:03

标签: database spring spring-data-jpa

所以我有一个在实体上运行的JPA存储库类。 spring docs不提供我可以在自动构建派生查询的对象上执行的所有操作。

所以,如果我有

if ($validator->passes()){
    $auth = DB::table('us')->where('username', '=', Input::get('username'))
      ->where('password', '=', Input::get('password'))->get()->first();
    // Try to log the user in.
    if ($auth){
        // Redirect to homepage
        //Auth::login($auth);
        Auth::attempt(['username' => $username, 'password' => $password], $remember);
        return Redirect::to('app/dashboard');
    }
  }
  else{
    return Redirect::to('login')->withErrors($validator);
  }

我需要知道还有什么支持代替'find',因为从实体中检索出'By'之后的所有内容。

是否有对实体支持的所有可能操作列表的引用?

1 个答案:

答案 0 :(得分:0)

请参阅query method document
一些示例查询方法:

public interface PersonRepository extends Repository<User, Long> {

  List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);

  // Enables the distinct flag for the query
  List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname);
  List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname);

  // Enabling ignoring case for an individual property
  List<Person> findByLastnameIgnoreCase(String lastname);
  // Enabling ignoring case for all suitable properties
  List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname);

  // Enabling static ORDER BY for a query
  List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
  List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
}