【问题标题】:how to create my queru in spring roo如何在 spring roo 中创建我的查询
【发布时间】:2013-04-05 06:41:40
【问题描述】:

我是初学者。

我正在尝试创建一个自定义查找器。并使用“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";
    }  

}

这不行。,,,,

【问题讨论】:

    标签: spring-roo spring-data spring-data-jpa


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      • 2015-08-16
      • 1970-01-01
      相关资源
      最近更新 更多