1.jpa支持native sql查询,所以你可以直接写sql查询得到数据
01 |
package com.zuidaima.springdata.repository;
|
03 |
import java.util.List;
|
04 |
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
05 |
import org.springframework.data.jpa.repository.Query;
|
06 |
import org.springframework.data.repository.PagingAndSortingRepository;
|
07 |
import org.springframework.data.repository.query.Param;
|
08 |
import com.zuidaima.springdata.entity.User;
|
11 |
* *@author javaniu 2013-06-04 22:27:22
|
14 |
public interface UserRepository extends PagingAndSortingRepository<User, Long>,
|
15 |
JpaSpecificationExecutor<User> {
|
16 |
@Query(value = "select * from user where id in(:ids)", nativeQuery = true)
|
17 |
List<User> findAllByIds(@Param("ids") List<Long> ids);
|
19 |
@Query(value = "from User where name=?1")
|
20 |
User findAllByName(String name);
|
2.jpa的PagingAndSortingRepository等内置类就支持分页查询
1 |
Page<T> findAll(Pageable pageable); |
3 |
Pageable pageable = new PageRequest(0, ps, sort);
|
通过new Pageable对象即可,注意page是从0开始
相关文章:
-
2021-07-25
-
2021-06-20
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2022-12-23