這是我UserRepository和查找功能今年春天數據查詢工作不
@Repository
public interface UserRepository extends CrudRepository<JPA_Users, Long> {
List<JPA_Users> findByName(String Name);
}
然後在控制器的功能之一,我嘗試訪問此發現的功能如下
@RequestMapping(value = "/jpadata1", method = RequestMethod.GET)
public String jpadata1(ModelMap map) {
UserRepository repository;
ApplicationContext context = new ClassPathXmlApplicationContext("beans1.xml");
repository = context.getBean(UserRepository.class);
Iterable usrs = repository.findByName("shahzad");
}
有列名與數據庫中的名稱,我有多個記錄與值shahzad我期待所有這些記錄將返回,但此函數不返回任何記錄沒有返回
Shahzad
坦率地說,您真的需要回到基礎知識並學習基本概念。Behing Spring:什麼是上下文,什麼是依賴注入等。從Spring bean重新創建一個新的上下文,然後查找存儲庫這個新的背景是完全錯誤的。 –