Code example of Java entity Class data Envelope
This article mainly explains the "Java entity class data seal code examples", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java entity class data seal code examples"!
1. Entity class
@ datapublic class PublishServiceType implements Comparable {/ * / private static final long serialVersionUID =-3572108154932898825L; / * * @ see [code] * @ comment Type ID * / private String code; / * * @ see {createtime} * @ comment creation time * / private java.util.Date createtime; / * * @ see {defaultmanual} * @ comment Service Type default user Manual * / private String defaultmanual / * * @ see {description} * @ comment Service Type description * / private String description; / * * @ see {id} * @ comment primary key * / private String id; / * * @ see {isdelete} * @ comment can you delete * / private Integer isdelete; / * @ see {lastmodifytime} * @ comment Last modified time * / private java.util.Date lastmodifytime / * * @ see {name} * @ comment service type name * / private String name; / * * @ see {parentid} * @ comment service type parent node * / private String parentid; / * * sort * / private Integer sort; private Listchildren;}
2. Data encapsulation
@ Override public List findList (String name) {Listlist = publishServiceTypeMapper.findByName (name); if (JudgeUtil.isEmpty (list)) {return null;} / / parent-child assembly return parentAndChildren (list);} private ListparentAndChildren (Listlist) {/ / topmost root node ListrootList = new ArrayList (); / / non-topmost root node ListbodyList = new ArrayList () For (PublishServiceType publishServiceType: list) {if (StringUtils.isBlank (publishServiceType.getParentid () {rootList.add (publishServiceType);} else {bodyList.add (publishServiceType);}} return getTree (rootList,bodyList) } public List getTree (ListrootList, ListbodyList) {if (! JudgeUtil.isEmpty (bodyList)) {/ / declare a map to filter the manipulated data Map map = new HashMap (bodyList.size ()); rootList.forEach (parent- > getChild (parent,bodyList,map)); return rootList;} else {return rootList;} private void getChild (PublishServiceType parent,ListbodyList, Map map) {ListchildList = new ArrayList () BodyList.stream () .filter (c->! map.containsKey (c.getId () .filter (c-> c.getParentid (). Equals (parent.getId () .forEach (c-> {map.put (c.getId (), c.getParentid ()); getChild (cMagnebodyListMagazine map); childList.add (c);}) Parent.setChildren (childList);}
3. Results
{"code": 20000, "message": "success", "data": [{"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "dc1d70b9eb7b4df3bbe8dcc6a93cbd57", "isdelete":-1, "lastmodifytime": null, "name": "basic Services", "parentid": "", "sort": 1 "children": [{"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "b1779671ef1b45e0a9a8a1edbff03f1e", "isdelete":-1, "lastmodifytime": null, "name": "data source service", "parentid": "dc1d70b9eb7b4df3bbe8dcc6a93cbd57", "sort": 2 "children": [{"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "2a38a8254ec348e9b54c9bf4622f23db", "isdelete": 1, "lastmodifytime": null, "name": "Test add Database Service 2", "parentid": "b1779671ef1b45e0a9a8a1edbff03f1e", "sort": null "children": []}}, {"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "d4f3b047dc2d467a9b404ded8acf4673", "isdelete": 1, "lastmodifytime": null, "name": "text_lsa", "parentid": "dc1d70b9eb7b4df3bbe8dcc6a93cbd57", "sort": null "children": []}}, {"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "af1b4a4d2f074fa19e1dae0a5540a5bf", "isdelete": 1, "lastmodifytime": null, "name": "Test add 1", "parentid": "", "sort": null, "children": []} {"code": null, "createtime": null, "defaultmanual": null, "description": null, "id": "62e15d859a224126884888a55df355a7", "isdelete": 1, "lastmodifytime": null, "name": "Test add 2", "parentid": "", "sort": null, "children": []}} Thank you for your reading The above is the content of "the code example of the Java entity class data envelope". After the study of this article, I believe you have a deeper understanding of the code example of the Java entity class data envelope, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!