Skip to content

Commit d16167e

Browse files
committed
[BAEL-10781] - Added code for spring data rest pagination
1 parent 4d90ca6 commit d16167e

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

spring-data-rest/src/main/java/com/baeldung/config/DbConfig.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ final Properties additionalProperties() {
6464

6565
@Configuration
6666
@Profile("h2")
67-
@PropertySource("persistence-h2.properties")
67+
@PropertySource("classpath:persistence-h2.properties")
6868
class H2Config {}
6969

7070
@Configuration
7171
@Profile("hsqldb")
72-
@PropertySource("persistence-hsqldb.properties")
72+
@PropertySource("classpath:persistence-hsqldb.properties")
7373
class HsqldbConfig {}
7474

7575

7676
@Configuration
7777
@Profile("derby")
78-
@PropertySource("persistence-derby.properties")
78+
@PropertySource("classpath:persistence-derby.properties")
7979
class DerbyConfig {}
8080

8181

8282
@Configuration
8383
@Profile("sqlite")
84-
@PropertySource("persistence-sqlite.properties")
84+
@PropertySource("classpath:persistence-sqlite.properties")
8585
class SqliteConfig {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.models;
2+
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.GeneratedValue;
6+
import javax.persistence.GenerationType;
7+
import javax.persistence.Id;
8+
9+
@Entity
10+
public class Subject {
11+
12+
@Id
13+
@GeneratedValue(strategy=GenerationType.IDENTITY)
14+
private long id;
15+
16+
@Column(nullable = false)
17+
private String name;
18+
19+
public Subject() {
20+
}
21+
22+
public long getId() {
23+
return id;
24+
}
25+
26+
public void setId(long id) {
27+
this.id = id;
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.repositories;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
5+
import org.springframework.data.repository.PagingAndSortingRepository;
6+
import org.springframework.data.repository.query.Param;
7+
import org.springframework.data.rest.core.annotation.RestResource;
8+
import com.baeldung.models.Subject;
9+
10+
public interface SubjectRepository extends PagingAndSortingRepository<Subject, Long> {
11+
12+
@RestResource(path = "nameContains")
13+
public Page<Subject> findByNameContaining(@Param("name") String name, Pageable p);
14+
15+
}

0 commit comments

Comments
 (0)