2017-08-10 18 views
-3

我有一个工作的JpaRepository作为一个接口和一个工作的Restcontroller。@Repository和@RestController一起

目前他们是两种类型,我喜欢将他们加入到一个!

这是我有:

@Repository 
@RestController("problem") 
public interface ProblemsController extends JpaRepository<Problem, Integer> { 

    @RequestMapping(value = "all", method = RequestMethod.GET) 
    List<Problem> findAll(); 
} 

但是,当我打电话http://localhost:8080/application/problem/all我得到一个404

怎么办?

+0

你尝试用@RequestMapping(值=“/所有”,方法= RequestMethod.GET) – cralfaro

+0

此外,我认为是一个错字,但你写applicatioin不应用 – cralfaro

+0

@Peter Rader看看我的解决方案 –

回答

2

您可以使用此way..but我没有得到什么正是你期待的。

import java.util.List; 

import org.springframework.data.repository.PagingAndSortingRepository; 
import org.springframework.data.repository.query.Param; 
import org.springframework.data.rest.core.annotation.RepositoryRestResource; 

@RepositoryRestResource(collectionResourceRel = "people", path = "people") 
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { 

    List<Person> findByLastName(@Param("name") String name); 

} 

这是充当一个Repositry和REST Web服务。

如果出现错误。您可以检查UI页面prperly定位这个接口或不

+0

如果有帮助,你可以选择答案。点击下面的小投票向下投票。 –

1

尝试@RestController

@Repository 
@RestController 
public interface ProblemsController extends JpaRepository<Problem, 
Integer> { 

    @RequestMapping(value = "/problem/all", method = RequestMethod.GET) 
    List<Problem> findAll(); 
} 

或者你可以试试这个添加/你RequestMapping不是:

@Repository 
    @RestController 
    @RequestMapping("/problem") 
    public interface ProblemsController extends JpaRepository<Problem, 
       Integer> { 

      @RequestMapping(value = "/all", method = RequestMethod.GET) 
      List<Problem> findAll(); 
    }