My Spring Boot project has a form at /albums/add
which looks like this:
<form method="post">
<input type="text" name="albumName"/>
<input type="submit" value="Add album"/>
</form>
I'm trying to deal with that request in the controller below:
@Controller
@RequestMapping(value = "/albums")
public class AlbumController {
(...)
@PostMapping("/add")
public String processAddAlbumForm(@RequestParam String albumName) {
albums.add(albumName);
return "redirect:";
}
}
However, Spring throws a 400 and tells me "Required String parameter 'albumName' is not present".
If I view the Network tab in my browser, I can see the request arrive with a value for albumName under the "Form Data" header, where the @RequestParam
annotation can't seem to find it.
My code is copied directly from this tutorial, but I'm worried something might have deprecated since it was made - any ideas?