0
我是初學者。如何在春季創建我的queru
我嘗試創建一個自定義查找器。並使用「repository jpa」命令。 這是我的倉庫:
@RooJpaRepository(domainType = Speaker.class)
public interface SpeakerRepository {
@Query("select u from Speaker u where username = :un")
public List<Speaker> findllAllSpeakersNamed(@Param("un") String lastname);
}
服務:
public class SpeakerServiceImpl implements SpeakerService {
@Autowired
SpeakerRepository speakerRepository;
public List<Speaker> findllAllSpeakersNamed(String lastName) {
return speakerRepository.findllAllSpeakersNamed(lastName);
}
}
和控制器:
@RequestMapping("/findASpeaker/**")
@Controller
public class FindASpeaker {
@Autowired
SpeakerServiceImpl speakerServiceImpl;
@RequestMapping(method = RequestMethod.POST, value = "{id}")
public void post(@PathVariable Long id, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
}
@RequestMapping
public String index(@RequestParam("lastname")String lastname) {
String Lastname=lastname;
ModelMap modle=new ModelMap();
List<Speaker> list = speakerServiceImpl.findllAllSpeakersNamed(Lastname);
modle.addAttribute("speakers",list);
return "findASpeaker/index";
}
}
這可不行,,,,