0
  @PostMapping("/save")
    public String handleNoteSave(@RequestParam(value = "noteId", required = false) Integer noteId,
                                 @RequestParam("notetitle") String notetitle,
                                 @RequestParam("notedescription")String notedescription,
                                 RedirectAttributes redirectAttributes,
                                 Authentication authentication) {
        User currentUser = userService.getUser(authentication.getName());
        noteService.saveNote(noteId, notetitle, notedescription, currentUser.getUserid());
        redirectAttributes.addFlashAttribute("activeTab", "notes");
        redirectAttributes.addFlashAttribute("changeSuccess", true);
        return "redirect:/home";

In console, I got this error :

Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'notetitle' for method parameter type String is not present]

In Url, http://localhost:8080/note/save

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Feb 18 19:20:57 KST 2022
There was an unexpected error (type=Bad Request, status=400).
Required request parameter 'notetitle' for method parameter type String is not present
org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'notetitle' for method parameter type String is not present
    at 

I am trying to create an instance of an Object and want ti store I into database, but I have got this error, how can I fix it?

  • send the parameter notetitle in you post. – pringi Feb 18 '22 at 10:54
  • Does this answer your question? [MissingServletRequestParameterException](https://stackoverflow.com/questions/45683153/missingservletrequestparameterexception) – pringi Feb 18 '22 at 10:54
  • @pringi I've just given require = false , defaultValue = "defaultNotetitle", like somethings but it's the same. I had no idea how to fix... – Nandara Soul Feb 18 '22 at 11:16
  • http://localhost:8080/note/save?notetitle=A&notedescription=B. You see a tutorial over spring web like https://spring.io/guides/gs/serving-web-content/ – pringi Feb 18 '22 at 11:23
  • @pringi Thank u so much – Nandara Soul Feb 18 '22 at 13:01
  • It's a bad idea to use query parameters for your save method. As you already use a POST request it's better to pass an object to the server using `ModelAttribute`. – Nico Van Belle Feb 23 '22 at 12:36

1 Answers1

0

I think you need to change @RequestParam("notetitle") String notetitle to

@RequestParam(name="notetitle) String notetitle.

vikas
  • 58
  • 6