I have one form which contains \"NO\" and \"Date\". It will be Dynamic form. While doing a batch update in Spring Boot JPA i got the \"java.time.format.DateTimeParseException: T
I think problem with your code, if I understood your input correctly, is that you're passing comma(,) separated date strings in LocalDate.parse(abc.getDate(),dateTimeFormatter)
.
You need to pass a single date each time to parse() method as it tries to format the provided string input with that of date formatter format and hence error occurs when it encounters comma(,) in input of "03/03/2020,03/03/2020".
Please refer to official documentation for same.
Below is something you can try :
String[] inputDates = abc.getDate().split[","];
for (String date : inputDates) {
// you can now use LocalDate.parse(abc.getDate(),dateTimeFormatter) here
// write your logic here.
}
I hope this helps you get your doubt cleared, if not let me know your exact question and I will try to help you out.
EDIT 1 For inserting data
Below is a way in which you can insert data,
Create a table which will store dates having 3 columns - id(P.K.), abc_id(F.K. ref. of ABC table), date (store single date here). Now let's say name of above table is abc_date_map, then reference this entity as OneToMany in your ABC entity. Like below,
@Entity
class ABC {
@Column(name="NO")
private String NO;
@Transient
private String date;
@Column(name="abc_date_map_id")
private List<AbcDateMap> abcDateMapEntityList;
//getters & setters//tostring
}
And your AbcDateMap entity will be like
@Entity
public class AbcDateMap{
@Column(name="abc_id")
private Integer abcId;
@Column(name="date")
private LocalDate localDate;
// getters setters
}
And your entity insertion logic will be like :
public Long insert(ABC abc) {
abc.setNo(/*something*/);
List<AbcDateMap> l = new ArrayList<>();
AbcDateMap abcDate = new AbcDateMap();
for (String date : abc.getDate().split(",")) {
abcDate.setLocalDate(/*parse date here and store*/);
abcDate.setAbcId(abc.getId());
}
abc.setAbcDateMapEntityList(l);
repo.save(abc);
}
Now above is not exact code, you will have to polish it out, might have syntax/semantics mistakes. Also you will need to change it according to your requirements.
Hope this helps you.
Good luck and happy learning !