我正在学习Spring-Data-Rest并尝试在我的Customer Repository中添加 countBy *** 功能。但是,当我尝试拨打api电话时:
//<app>/customers/search/countByFirstnameUsingQuery?firstname=Dave
或者
//<app>/customers/search/countByFirstname?firstname=Dave
我收到 500内部服务器错误。
以下是我的存储库的样子
public interface CustomerRepository extends JpaRepository<Customer, Long>{
Customer findByEmailAddress(@Param("emailAddress") EmailAddress emailAddress);
@Query("select c from Customer c where c.firstname = :firstname")
Customer findByFirstNameUsingQuery(@Param("firstname") String firstname);
public long countByFirstname(@Param("firstname") String firstname);
@Query("select count(c) from Customer c where c.firstname = :firstname")
Long countByFirstnameUsingQuery(@Param("firstname") String firstname);
}
以下是我的客户类
@Entity
public class Customer extends AbstractEntity {
private String firstname, lastname;
@Column(unique = true)
private EmailAddress emailAddress;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "customer_id")
private Set<Address> addresses = new HashSet<Address>();
服务器上没有异常。以下是服务器日志的所有内容 但是,下面是日志的内容。
2014-05-08 13:02:05,551 DEBUG rest.webmvc.RepositoryRestHandlerMapping: 219 - Looking up handler method for path /customers/search/countByFirstname
2014-05-08 13:02:05,567 DEBUG rest.webmvc.RepositoryRestHandlerMapping: 226 - Returning handler method [public org.springframework.http.ResponseEntity<org.springframework.hateoas.Resources<?>>
org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.web.context.request.WebRequest,java.lang.String,org.springframework.data.domain.Pageable
如果需要进一步的详细信息,请告诉我。
非常感谢上述任何意见。
当我访问时,我收到“500内部服务器错误”。 对我来说,看起来Spring数据休息不支持将计数公开为rest api。