将数据库数据转换成表格html

2019年9月6日 22点热度 0条评论 来源: lie_123

将数据库数据转换成表格html

将数据库数据转换成表格html

  /** * 将数据库数据转换成表格html * @param maplist * @return */
    private String getTable(List<LinkedHashMap<String, Object>> maplist,String title){ 
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<meta name=''viewport'' content=''width=device-width, minimum-scale=1, maximum-scale=1''>");
        stringBuilder.append("<style type=''text/css''>");
        stringBuilder.append(" table{");
        stringBuilder.append(" font: normal 9pt auto ''Trebuchet MS'', Verdana, Arial, Helvetica, sans-serif;");
        stringBuilder.append(" color: #4f6b72;");
        stringBuilder.append(" padding: 2px 10px;");
        stringBuilder.append(" margin: 0;");
        stringBuilder.append(" border:1px;cellspacing:0;cellpadding:0;align:center;border-collapse:collapse;");
        stringBuilder.append(" width:auto;");
        stringBuilder.append(" }");
        stringBuilder.append(" table.th{height:22px;background-color:#ECECE6}");
        stringBuilder.append(" td,th {");
        stringBuilder.append(" border-right: 1px solid #C1DAD7;");
        stringBuilder.append(" border-bottom: 1px solid #C1DAD7;");
        stringBuilder.append(" height:20px;");
        stringBuilder.append(" color: #000;");
        stringBuilder.append(" }");
        stringBuilder.append(" tr.alt {");
        stringBuilder.append(" background: #F5FAFA;");
        stringBuilder.append(" color: #797268;");
        stringBuilder.append(" }");
        stringBuilder.append("</style>");

        stringBuilder.append("<table>");
        stringBuilder.append("<tr><td colspan="+ (maplist.get(0).size()-2)+" align=''left'' style=''border-right:none;''>" + title + "</td></tr>");
        for (int i = 0; i < maplist.size(); i++) { 
            stringBuilder.append("<tr>");
            if (i == 0) { 
                for (String key : maplist.get(i).keySet()) { 
                    if (CommonUtil.isChineseByRange(key)) { 
                        stringBuilder.append("<th width=''80px''>");
                        stringBuilder.append(key);
                        stringBuilder.append("</th>");
                    }
                }
                stringBuilder.append("</tr>");
                stringBuilder.append("<tr>");
            }

            for (String key : maplist.get(i).keySet()) { 
                if (CommonUtil.isChineseByRange(key)) { 
                    stringBuilder.append("<td>");
                    stringBuilder.append(maplist.get(i).get(key));
                    stringBuilder.append("</td>");
                }
            }
            stringBuilder.append("</tr>");
        }
        stringBuilder.append("</table>");
        return stringBuilder.toString();
    }



   /** * 是否全是汉字<br> * 根据汉字编码范围进行判断<br> * CJK统一汉字(不包含中文的,。《》()“‘'”、!¥等符号)<br> * * @param str * @return */
    public static boolean isChineseByRange(String str) { 
        if (str == null) { 
            return false;
        }
        char[] ch = str.toCharArray();
        for (char c : ch) { 
            if (c < 0x4E00 || c > 0x9FBF) { 
                return false;
            }
        }
        return true;
    }
    原文作者:lie_123
    原文地址: https://blog.csdn.net/lie_123/article/details/95478831
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。