【问题标题】:Get Controller settings properly in SpringBoot在 Spring Boot 中正确获取控制器设置
【发布时间】:2018-07-11 14:06:17
【问题描述】:

当我尝试显示指定用户的假期时。我有

 URL: localhost:8080/api/user -> this getting me all users.

 localhost:8080/api/user/userId (like 22)/vacation -> this should be getting me all Vacations for this user.

我在有这个方法的地方创建了 VacationController

@GetMapping("/api/user/{userId}/vacation")
public Vacation getVacations(@PathVariable Long userId) {
    return vacationService.findAllByUserId(userId);
}

在我的服务中,此方法回答存储库具有:

@Repository
public interface VacationRepository extends JpaRepository<Vacation, Long> {
Vacation findAllByUserId(Long userId);
}

根据我在互联网上的研究,我已经正确编码,但它不起作用。我做错了什么?

【问题讨论】:

    标签: java spring-boot spring-repositories


    【解决方案1】:

    “它不起作用”是什么意思?有什么错误代码吗?

    尝试改变:

     Vacation findAllByUserId(Long userId);
    

    to(findAll 返回集合):

    List<Vacation> findAllByUserId(Long userId);
    

    【讨论】:

    • 请在您的问题正文中发布错误
    • @Deeadline 发布项目构建文件(maven 为 pom.xml,gradle 为 gradle.build)和用户实体
    猜你喜欢
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2020-09-26
    • 2017-03-16
    • 2019-08-15
    • 2016-07-20
    相关资源
    最近更新 更多