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 Long
s. 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
How to Send Date in Rest API in Post Method
Is There an Invisible Character That Is Not Regarded as Whitespace
How to Make Program to Continue Running After Exception
403 Forbidden When I Try to Post to My Spring API
How to Update Each Element in a List in Java 8 Using Stream API
How to Know If All the Variables in a Class Are Null
How to Set a Timeout on a Spring Boot Rest API
How to Use Variables in One Method into Another Method
How to Bypass Google Recaptcha for Testing Using Selenium
How to Upload a File and Json Data in Postman
How to Determine If a List of String Contains Null or Empty Elements
How to Pass JavaScript Values to Scriptlet in Jsp
How to Print Out All the Elements of a List in Java
Remove Duplicates from a List of Objects Based on Property in Java 8
How to Fill Hashmap from Java Property File With Spring @Value