Blame view

src/main/java/com/zteits/oa/util/pagepaper/PageBeanUtil.java 2.01 KB
1b9e8898   王富生   提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  package com.zteits.oa.util.pagepaper;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.beans.BeanUtils;
  
  import com.github.pagehelper.PageInfo;
  import com.zteits.oa.api.base.bean.PageBean;
  
  /**
   * 分页插件结果转换工具类.<br/>
   * 
   * Copyright: Copyright (c) 2017  zteits
   * 
   * @ClassName: PageBeanUtil.java
   * @Description: 
   * @version: v1.0.0
   * @author: wangfs
   * @date: 2017419   下午4:03:33 
   * Modification History:
   * Date             Author          Version            Description
   *---------------------------------------------------------*
   * 2017419      wangfs           v1.0.0               创建
   */
  public class PageBeanUtil {
  
  	/**
  	 * PageInfo 转换成PageBean.<br/>
  	 * @param form  PageInfo<R> 对象.<br/>
  	 * @param to PageBean<L> 对象.<br/>
  	 * @param clazz 
  	 */
  	public static<R,L> void copyProperties(PageInfo<R> form,PageBean<L> to,Class<L> clazz){
  		if(form != null && to != null  &&  clazz != null){
  			List<L> list = new ArrayList<L>();
  			if(!org.springframework.util.CollectionUtils.isEmpty(form.getList())){
  				for(R source:form.getList()){
  					if(source == null){
  						continue;
  					}
  					try {
  						L target = clazz.newInstance();
  						BeanUtils.copyProperties(source, target);
  						list.add(target);
  					} catch (InstantiationException e) {
  						e.printStackTrace();
  					} catch (IllegalAccessException e) {
  						e.printStackTrace();
  					}
  				}
  				to.setDataList(list);
  				to.setPageNum(form.getPageNum());
  				to.setPageSize(form.getPageSize());
  				to.setPages(form.getPages());
  				to.setPageTotals(Integer.valueOf(String.valueOf(form.getTotal())));
  			}else{
  				to.setDataList(list);
  				to.setPageNum(form.getPageNum());
  				to.setPageSize(form.getPageSize());
  				to.setPages(form.getPages());
  				to.setPageTotals(Integer.valueOf(String.valueOf(form.getTotal())));
  			}
  		}else{
  			try {
  				throw new Exception("源对象,目标对象,clazz 不能为空!");
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  	}
  	
  	
  	
  
  }