0

i am a beginner.

I am try to created a custom finder. and used "repository jpa " command. this is my repository:

    @RooJpaRepository(domainType = Speaker.class)
public interface SpeakerRepository {
    @Query("select u from Speaker u where username = :un")  
    public List<Speaker> findllAllSpeakersNamed(@Param("un") String lastname); 
    } 

Service:

public class SpeakerServiceImpl implements SpeakerService {
@Autowired 
SpeakerRepository speakerRepository;
public List<Speaker> findllAllSpeakersNamed(String lastName) {
    return speakerRepository.findllAllSpeakersNamed(lastName);
 }
} 

and controller:

@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";
    }  

}

This can not work.,,,,

4

1 回答 1

0

您的存储库是一个接口。Spring Data 应该根据方法的名称自动检测查询,例如“List findUsersByNameDesc(String name);” 将自动创建一个方法来查询具有给定名称的所有用户。@Query 只是告诉它不要猜测查询,而是使用您提供的查询。一个例子可以在这里找到

于 2013-04-08T19:57:29.037 回答