使用开始和结束LocalDate参数获取记录

时间:2018-06-19 14:21:31

标签: java spring-data-jpa spring-data-rest localdate

public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String username;

    @OneToMany(mappedBy = "user")
    private Set<Login> login;
}


public class Login {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private LocalDateTime loginTime;

    @ManyToOne
    private User user;
}

@RepositoryRestResource(collectionResourceRel = "user", path = "user")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {

    List<User> findAll();

    // List<User> List<User> findByLogin_LoginTimeGreaterThanEqualAndLogin_LoginTimeLessThanEqual(@Param("loginTime") LocalDate start, @Param("loginTime") LocalDate end);    }

我想找到dateTime大于或等于提供的start参数值且小于或等于提供的end参数值的所有唯一用户。

http://localhost:8080/api/users?start=YYYYMMDD&end=YYMMDD


当我尝试

curl -X GET --header 'Content-Type: application/json' --header 'Accept: application/hal+json' -d '2018-06-19' 'http://localhost:8080/test/user/search/findAllByLogin_LoginTimeGreaterThanEqualAndLogin_LoginTimeLessThanEqual

我知道

  

“值不能为空!”

我正在使用1.5.4-RELEASE

0 个答案:

没有答案