0
我有一個Spring引導的問題。 我創建了實體和存儲庫,但存儲庫中的方法findByName不起作用。 我的網址:findByName不工作[Spring boot]
http://localhost:8080/student/search/findByName?name=Artem 在Google chrome:找不到localhost,但搜索已被映射。
實體:
@Getter @Setter
@Entity @Table(name = "Student")
public class Student extends BaseEntity{
private String name;
private String dateOfBirthDay;
private String sex;
private String phoneNumber;
}
BaseEntity:
@Getter
@Setter
@MappedSuperclass
public class BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE) @Column protected Long id;
我的倉庫:
@RepositoryRestResource(collectionResourceRel = "student", path = "student")
public interface StudentRepository extends PagingAndSortingRepository<Student, Long> {
Student findByName(@Param("name") String name);
}
應用:
@SpringBootApplication
@EnableTransactionManagement
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Application.yaml:
spring:
application:
name: students
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/students
username: postgres
password: postgres
jpa:
hibernate:
ddl-auto: update
server:
port: 8080
@javaguy閱讀關於RepositoryRestResource,它是像控制器一樣工作。 – Mello007