Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

arraylist - How to convert some String fields of a list of entities to date while iterating in Java 8

I am having a list of entities which having various values including some string fields which i want to convert to as date.

N_year_month=20010125, N_sequence_num=1, M_sequence_num=0, N_creation_date=20010109, N_check_date=20010211, _status=H, _frequency=A, _record=0

My requirement is to convert the N_year_month,N_creation_date,N_check_date into date while returning the list.

I am posting the code i have written

DateTimeFormatter formatter_1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");

public List<NEntity> fetch(List<SearchCriteria> params){
    CriteriaQuery<NEntity> query = getNListDetailEntityCriteriaQuery(params);
    List<NEntity> nEntityDetailsList = entityManager.createQuery(query).getResultList();//in this line i am getting the data from the database 
    pmmEntityDetailsList.stream()
    .map(i->LocalDate.parse(i.N_year_month(),formatter_1))
    .collect(Collectors.toList());// Here i have tried to convert the String into date
     int count = entityManager.createQuery(query).getResultList().size();
     entityManager.close();
     return nEntityDetailsList;
}

I have tried to convert one field into date using stream api of Java 8 , but i am having exception.My exception is below

{
"errorMessage": "Something went wrong!",
"errorDetails": "Text '20010125' could not be parsed at index 0",
"timestamp": "2021-01-06 10:29:48",
"status": 500
}

How i can convert these 3 fields N_year_month,N_creation_date,N_check_date into Date(yyyy-mm-dd format) while returning the list nEntityDetailsList;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...