⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilmethod.java

📁 信息发布 发布系统 动态的菜单 和 信息统计
💻 JAVA
字号:
package com.xuntian.material.util;

import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

public final class UtilMethod {
    public static int getResultSetRows(ResultSet rs) throws SQLException {
        int length = 0;
        if (rs.next()) {
            rs.last();
            length = rs.getRow();
        }
        rs.beforeFirst();
        return length;
    }

    public static String jsArrayFormat(List<List<String>> data) {
        StringBuffer result = new StringBuffer("new Array(");
        List<String> record;
        int lenRecord = data.size();
        for (int i = 0; i < lenRecord; i++) {
            record = data.get(i);
            if (i > 0) {
                result.append(",\n");
            }
            result.append("\tnew Array(");
            int lenValue = record.size();
            for (int j = 0; j < lenValue; j++) {
                if (j > 0) {
                    result.append(", ");
                }
                result.append("'").append(record.get(j)).append("'");
            }
            result.append(")");
        }
        result.append(")");
        return result.toString();
    }

    public static String beanDateFormat(String date) {
        if (date == null || date.equals("")) {
            return "1900-01-01";
        } else if (date.length() > 10) {
            return date.substring(0, 10);
        } else {
            return date;
        }
    }

    public static void copyProperties(Object to, Object from) {
        try {
            BeanUtils.copyProperties(to, from);
        } catch (IllegalAccessException e) {
            LogUtil.getLogger(UtilMethod.class).error(
                    "copy from one obj to another: 'FROM' wrong!");
        } catch (InvocationTargetException e) {
            LogUtil.getLogger(UtilMethod.class).error(
                    "copy from one obj to another: 'TO' wrong!");
        }
    }

    public static String moneyFormat(String money) {
        String[] numbers = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
        String[] units = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟",
                "亿", "拾", "佰", "仟", "万", "拾", "佰", "仟" };
        int position = money.indexOf('.');
        if (position < 0) {
            position = money.length();
        }
        StringBuffer result = new StringBuffer();
        char c;
        int len = money.length();
        position += 1;
        for (int i = 0; i < len; i++) {
            c = money.charAt(i);
            if (c == '.') {
                continue;
            }
            result.append(numbers[c - '0']);
            if (position >= 0 && (c > '0' || position % 4 == 2)) {
                result.append(units[position]);
            }
            position--;
        }
        result.append("整");
        String out = result.toString();
        while (out.indexOf("零零") >= 0) {
            out = out.replaceAll("零零", "零");
        }
        out = out.replaceAll("零亿", "亿");
        out = out.replaceAll("零万", "万");
        out = out.replaceAll("零元", "元");
        out = out.replaceAll("亿万", "亿");
        out = out.replaceAll("零整", "整");
        return out;
    }

    /**
     * @param in
     *            传入的字符串
     * @param len
     *            传出的长度(前补0)
     * @return 前补0后的string
     */
    public static String formatToLen(String in, int len) {
        int inLen = in.length();
        StringBuffer out = new StringBuffer();
        for (int i = 0; i < len - inLen; i++) {
            out.append("0");
        }
        out.append(in);
        return out.toString();
    }

    public static String htmlFormat(String string) {
        if (string == null || string.equals("")) {
            return "&nbsp;";
        }
        StringBuffer sb = new StringBuffer();
        int length = string.length();
        char c;
        for (int i = 0; i < length; i++) {
            c = string.charAt(i);
            switch (c) {
            case '&':
                sb.append("&amp;");
                break;
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            case ' ':
                sb.append("&nbsp;");
                break;
            case '\n':
                sb.append("<br>\n");
                break;
            default:
                sb.append(c);
            }
        }
        return sb.toString();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -