Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tool class of how to convert VO to PO in java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to convert VO into PO tools in java", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to convert VO into PO tools in java" this article.

Recently, the conversion between VO and PO is required for data backhaul and storage in the project, so org.springframework.beans.BeanUtils is encapsulated to meet the needs of the project, such as one-to-one and many-to-many conversion. The code is as follows:

Public class CopyUtil {

/ / replication of multiple entities

Public static List copyList (List source, Class clazz) {

List target = new ArrayList ()

If (! CollectionUtils.isEmpty (source)) {

If (! CollectionUtils.isEmpty (source)) {

For (Object c: source) {

T obj = copy (c, clazz)

Target.add (obj)

}

}

}

Return target

}

/ / replication between individual entities

Public static T copy (Object source, Class clazz) {

If (source = = null) {

Return null

}

T obj = null

Try {

Obj = clazz.newInstance ()

} catch (Exception e) {

E.printStackTrace ()

}

BeanUtils.copyProperties (source, obj)

Return obj

}

}

These are all the contents of this article entitled "how to convert VO to PO in java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report