相关疑难解决方法(0)

如何使用Spring Data REST进行高级搜索?

我的任务是使用Spring Data REST进行高级搜索.我该如何实现它?

我设法做了一个简单的搜索方法,就像这样:

public interface ExampleRepository extends CrudRepository<Example, UUID>{

    @RestResource(path="searchByName", rel="searchByName")
    Example findByExampleName(@Param("example") String exampleName);

}
Run Code Online (Sandbox Code Playgroud)

如果我必须简单地去网址,这个例子很有效:

.../api/examples/search/searchByName?example=myExample
Run Code Online (Sandbox Code Playgroud)

但是,如果要搜索多个字段,我该怎么做?

例如,如果我的Example类有5个字段,那么我应该使用所有possibiles文件进行高级搜索?

考虑一下这个:

.../api/examples/search/searchByName?filed1=value1&field2=value2&field4=value4
Run Code Online (Sandbox Code Playgroud)

还有这个:

.../api/examples/search/searchByName?filed1=value1&field3=value3
Run Code Online (Sandbox Code Playgroud)

我需要做些什么才能以适当的方式实现此搜索?

谢谢.

java spring java-8 spring-data-rest

13
推荐指数
4
解决办法
3万
查看次数

Spring Data Rest - 按嵌套属性排序

我有一个使用Spring Boot 1.5.1和Spring Data Rest的数据库服务.我将我的实体存储在MySQL数据库中,并使用Spring的PagingAndSortingRepository通过REST访问它们.我发现表明支持按嵌套参数排序,但我找不到按嵌套字段排序的方法.

我有这些课程:

@Entity(name = "Person")
@Table(name = "PERSON")
public class Person {
    @ManyToOne
    protected Address address;

    @ManyToOne(targetEntity = Name.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "NAME_PERSON_ID")
    protected Name name;

    @Id
    protected Long id;

    // Setter, getters, etc.
}

@Entity(name = "Name")
@Table(name = "NAME")
public class Name{

    protected String firstName;

    protected String lastName;

    @Id
    protected Long id;

    // Setter, getters, etc.
}
Run Code Online (Sandbox Code Playgroud)

例如,使用该方法时:

Page<Person> findByAddress_Id(@Param("id") String id, Pageable pageable);
Run Code Online (Sandbox Code Playgroud)

并调用URI http:// localhost:8080/people/search/findByAddress_Id?id = …

spring spring-data spring-data-rest spring-boot

12
推荐指数
2
解决办法
5651
查看次数