Is there an easy way to turn empty form input into null strings in java? I'm using spring mvc and SimpleJdbcInsert to insert the object into a MySQL database. I'd like to set the blank input to NULL in the database rather than ''. I have quite a few fields, and I'm hoping for a way to do this without manually checking every value.
Thanks!
edit - So I'm an idiot. Several errors combined on my part led me to believe the correct answers below were not correct. I'd written a propertyEditorSupport like this:
class StringEditor extends PropertyEditorSupport {
public void setAsText(String text) {
String value = text.trim();
if ("" == value) {
setValue(null);
}
else {
setValue(value);
}
}
}
Two problems - first, no getAsText, so my form was getting populated with "null" strings! 2nd, my equality check is C++, not java. When I tried the recommended setter, I just reloaded the post, which already contained the "null" strings. Once I cleaned all that up, everything started working. Thanks for the help, and sorry for my "operator error"!
Brett