mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
Fixed handling of java.sql.Date field type
This commit is contained in:
parent
c205e4948c
commit
ad95f2434c
@ -496,6 +496,7 @@ public class DefaultDbAdminController {
|
||||
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
|
||||
attr.addFlashAttribute("params", params);
|
||||
} catch (DbAdminException e) {
|
||||
e.getCause().printStackTrace();
|
||||
attr.addFlashAttribute("errorTitle", "Error");
|
||||
attr.addFlashAttribute("error", e.getMessage());
|
||||
attr.addFlashAttribute("params", params);
|
||||
|
@ -386,7 +386,10 @@ public class DbObjectSchema {
|
||||
|
||||
Object parsedFieldValue =
|
||||
getFieldByName(param).getType().parseValue(params.get(param));
|
||||
|
||||
System.out.println(param);
|
||||
System.out.println(parsedFieldValue);
|
||||
if (parsedFieldValue != null)
|
||||
System.out.println(parsedFieldValue.getClass());
|
||||
if (parsedFieldValue != null && getFieldByName(param).isSettable()) {
|
||||
setter.invoke(instance, parsedFieldValue);
|
||||
}
|
||||
|
@ -18,13 +18,13 @@
|
||||
|
||||
package tech.ailef.dbadmin.external.dbmapping.fields;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
||||
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||
|
||||
public class DateFieldType extends DbFieldType {
|
||||
@Override
|
||||
@ -35,11 +35,12 @@ public class DateFieldType extends DbFieldType {
|
||||
@Override
|
||||
public Object parseValue(Object value) {
|
||||
if (value == null || value.toString().isBlank()) return null;
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
|
||||
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
|
||||
try {
|
||||
return format.parse(value.toString());
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
LocalDate localDate = LocalDate.parse(value.toString());
|
||||
return Date.valueOf(localDate);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new DbAdminException("Invalid date " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user