Spring Boot - 将 GetMapping 到具有不同路径的相同方法的更简单方法



目前我的控制器看起来像这样。

@RequestMapping("会员"( 公共类成员控制器 { private ArrayListmemberList = new ArrayList<>((; @GetMapping("( 公共字符串索引1(模型模型( { model.addAttribute(memberList(; 返回"成员/成员索引"; } @GetMapping("索引"( 公共字符串索引2(模型模型( { model.addAttribute(memberList(; 返回"成员/成员索引"; } }

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

提前致谢:)

编辑:我已经看到它工作了@RequestMapping

您可以使用@GetMapping的值,如下所示:

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

我立即自己修复了它。

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

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

最新更新