Is there a reason my @GetMapping("/") doesn't work, but @GetMapping("") does work?

72 views Asked by At

As stated in the question, my GetMapping only works when I do not input any parameters. I've also had some weird errors with some PostMapping actions requiring more explicit path declarations in my form action tags.

I don't know what to even reinstall if this is an issue with a faulty installation, I've reinstalled my java and used both eclipse(spring tool suite 4) and visual studio code with no changes in the nature of the errors I'm seeing.

Any help greatly appreciated.

1

There are 1 answers

0
Bill Mair On

Your question needs some serious improvements, but here is a guess.

What Framework: "I'm using Spring"

Based on the annotations, I think that that is a given.

My Controller has the @RequestMapping("some/resource")

@RequestMapping("some/resource")
@Controller
public class ResourceController { .... }

So, we know what is being referenced "some/resource"

You have an access method for "some/resource"

@GetMapping("/")
public Result getResource() {
     return someValue;
}

And you are wondering why the additional / is not needed?

@GetMapping
public Result getResource() {
     return someValue;
}

Spring does not know what it should do, what should "some/resource//" deliver?

The @GetMapping is added to the @ResourceMapping. That is why it doesn't work, the path doesn't make any sense.