Failed to Convert Value of Type 'Java.Lang.String' to Required Type 'Long'; Nested Exception Is Java.Lang.Numberformatexception: for Input String: ""

Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long

The number you are trying to convert to java.lang.Long is -26.2041028.

Your number contains a .(decimal). This is not allowed for Longs. You need to use java.lang.Double.

And also succeed your number with an L for Long or a D for Double for static initializations. Even though not required, it makes the code more readable.

Like, -26.2041028D for Double.

Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: ""

you need to add default value for codeCompte2

in agent.html

<input type="text" name="codeCompte2" value="0" /> // add default value 

Failed to convert value of type 'java.lang.String' to required type 'int'; For input string: "save"

It sounds to me like you probably have a @RequestMapping to a resource something like "/{id}" and when you are trying to hit your "/save" resource instead of mapping it to your controller method you showed in your question it is trying to parse the word "save" as an integer id for the resource "/{id}".

To fix this you should rename this previous resource mapping from "/{id}" to something with a suitable prefix "/something/{id}.

Failed to convert value of type 'java.lang.String' to required type 'long';

The action attribute of the <form> tag does not have the id path variable that your @PostMapping requires.

Adjust to use something like:

<form th:action="@{/editKursInfo/{id}(id=${edit.id})}" 
method="POST"
th:object="${edit}">

PS: In your @GetMapping method, you have the same Java object under 2 keys:

model.addAttribute("kurs", kurs);
model.addAttribute("edit", kurs);

There is no need for that.

PS 2: It is better not to use edit in your URL. I would suggest to use /kurse/{id} or /kurseinfo/{id}. The fact that you are editing something or just viewing something is determined by the GET or POST mapping.



Related Topics



Leave a reply



Submit