0
votes

currently my Controller looks like this.

@RequestMapping("members")
public class MembersController {

    private ArrayList<Member> memberList = new ArrayList<>();

    @GetMapping("")
    public String index1(Model model) {
        model.addAttribute(memberList);
        return "members/memberIndex";
    }

    @GetMapping("index")
    public String index2(Model model) {
        model.addAttribute(memberList);
        return "members/memberIndex";
    }
}

Is there a easier way to have one index-method for two different paths "localhost:port/members" & "localhost:port/members/index"? Can I annotate two values for one method in general?

Thanks in advance :)

Edit: I have seen it work for @RequestMapping

2

2 Answers

2
votes

You can use the value of @GetMapping as follows:

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

I fixed it myself immediatly.

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

Didn't notice an array is necessary.