【问题标题】:Spring Boot - Easier way of GetMapping to the same method with different PathsSpring Boot - GetMapping 到具有不同路径的相同方法的更简单方法
【发布时间】:2020-10-12 13:51:36
【问题描述】:

目前我的 Controller 是这样的。

@RequestMapping("成员")
公共类成员控制器 {

    私有 ArrayList memberList = new ArrayList();

    @GetMapping("")
    公共字符串索引1(模型模型){
        model.addAttribute(memberList);
        返回“成员/成员索引”;
    }

    @GetMapping("索引")
    公共字符串索引2(模型模型){
        model.addAttribute(memberList);
        返回“成员/成员索引”;
    }
}

有没有一种更简单的方法可以为两个不同的路径“localhost:port/members”和“localhost:port/members/index”使用一个索引方法?一般来说,我可以为一种方法注释两个值吗?

提前致谢:)

编辑:我已经看到它适用于@RequestMapping

【问题讨论】:

    标签: java spring spring-boot thymeleaf


    【解决方案1】:

    您可以按如下方式使用@GetMapping 的值:

    @GetMapping(value = {"/", "/index"})
    

    【讨论】:

      【解决方案2】:

      我自己马上修好了。

      @GetMapping({"", "index"})
      

      没有注意到数组是必需的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-25
        • 1970-01-01
        • 2016-09-21
        • 2021-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多