数据库字段转驼峰命名

    public static void main(String[] args) {
        String[] strings = {"DATA_SOURCE", "APP_APPLICATION_ID", "APP_BARCODE", "APP_BIZ_ORG_CODE", "APP_COLLECTION_LOCATION", "APP_COLLECTION_LOCATION_NAME", "APP_CUSTOMER_ID", "APP_CUSTOMER_NAME", "APP_CREATION_DATE", "ATS_APP_TEST_SET_ID", "ATS_TEST_ITEM_CODE", "ATS_TEST_ITEM_NAME", "ATS_SPECIMEN_STYLE_CODE", "ATS_CHECK_DATE", "ATS_TEST_ITEM_NAME_ALT", "ATS_PATS_TEST_ITEM_CODE", "ATS_PATS_TEST_ITEM_NAME", "ATS_PATS_TEST_ITEM_NAME_ALT", "ATS_TEST_ORG_CODE", "BS_BIG_BARCODE", "SAMPLING_TIME", "WJW_WJW_NAME", "TN_TEST_NUMBER_ID", "TN_EXPERIMENT_NO", "XG_XIN_GUAN_APP_DETAIL_ID", "XG_SAMPLING_MECHANISM_CODE", "XG_SAMPLING_MECHANISM_NAME", "XG_BARCODE", "XG_NAME", "XG_SEX", "XG_AGE", "XG_PATIENT_PHONE", "XG_NATIONALITY", "XG_DOMICILE", "XG_ADDRESS", "XG_DOCUMENT_TYPE", "XG_DOCUMENT_NUMBER", "XG_SOURCE_PERSONNEL", "XG_IDENTITY", "XG_ENTRY_FOURTEEN", "XG_SAMPLING_TIME", "XG_SAMPLING_LOCATION", "XG_COMPANY", "XG_ARCHIVE_BASE_DATE", "XG_BIZ_ORG_CODE", "XG_CREATED_BY", "XG_CREATION_DATE", "XG_LAST_UPDATED_BY", "XG_LAST_UPDATE_DATE", "XG_RECORD_VERSION", "XG_DELETED_FLAG", "XG_DELETED_BY", "XG_DELETION_DATE", "XG_INSURANCE_TYPE", "XG_INSURANCE_AREA", "XG_INSURANCE_CATEGORY", "XG_KMCS_BARCODE", "XG_SETTLEMENT_TYPE", "XG_CHECK_TIME", "XG_RELATION_ID", "XG_GROUP_CODE", "XG_BIND_MAN_PHONE", "XG_IMPORT_FLAG", "XG_FLAG", "XG_TEMP_FLAG", "XG_SECOND_DOCUMENT_TYPE", "XG_SECOND_DOCUMENT_NUMBER", "XG_COMPANY_ID", "XG_PERSONNEL_TYPE", "XG_PATIENT_NO", "XG_BED_NO", "XG_CUSTOMER_DOCTOR", "XG_VACCINATION_TIME", "XG_VACCINATION_SITE", "XG_EMERGENCY_CONTACT", "XG_AREA", "XG_OPEN_ID", "D_APP_DETAIL_ID", "D_NAME", "D_SEX", "D_AGE", "D_BIRTHDAY", "D_NATIONALITY", "D_PATIENT_PHONE", "D_HOSPITAL_BARCODE", "D_HOSPITAL_ID", "D_NATION", "D_PATIENT_ADDR", "D_ID_CARD", "D_CUSTOMER_DEPT", "D_TIME_POINT", "D_PATIENT_NO", "D_ID_CARD_TYPE", "D_DIAGNOSE", "D_CUSTOMER_DOCTOR", "RST_TEST_RESULT_ID", "RST_CREATION_DATE", "RST_TEST_RESULT", "RST_REF_REPORT_DIS_CN", "RST_CHECK_DATE", "RST_RECORD_TIME", "RST_RECORDED_BY_NAME", "RST_CHECKED_BY_NAME", "RST_APPROVED_BY_NAME", "RST_APPROVED_TIME", "R_REPORT_ID", "R_REPORT_ODD", "R_RELEASE_BY_NAME", "INSERT_DATE", "LAST_UPDATE_DATE", "R_RELEASE_TIME", "T_TASK_ID", "IOS_FROM_ID", "IOS_TO_ID", "D_SAMPLING_TIME", "RST_LAST_UPDATE_DATE"};

        String col = "<result column=\"%s\" property=\"%s\"></result>";

        for (String t : strings) {
            System.out.println(
                    String.format(col, t, toHump(t))
            );
        }
    }
    private static String toHump(String s) {
        s = s.toLowerCase();

        while (s.contains("_")) {
            int index = s.indexOf("_");
            String target = s.substring(index + 1, index + 2);
            s = s.replace(("_" + target), target.toUpperCase());
        }

        return s;
    }
posted @ 2021-07-30 10:19  eedc  阅读(429)  评论(0编辑  收藏  举报