ColUtil.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2019-2020 Zheng Jie
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package me.zhengjie.utils;
  17. import org.apache.commons.configuration.*;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. /**
  21. * sql字段转java
  22. *
  23. * @author Zheng Jie
  24. * @date 2019-01-03
  25. */
  26. public class ColUtil {
  27. private static final Logger log = LoggerFactory.getLogger(ColUtil.class);
  28. /**
  29. * 转换mysql数据类型为java数据类型
  30. *
  31. * @param type 数据库字段类型
  32. * @return String
  33. */
  34. static String cloToJava(String type) {
  35. Configuration config = getConfig();
  36. assert config != null;
  37. return config.getString(type, "unknowType");
  38. }
  39. /**
  40. * 获取配置信息
  41. */
  42. public static PropertiesConfiguration getConfig() {
  43. try {
  44. return new PropertiesConfiguration("generator.properties");
  45. } catch (ConfigurationException e) {
  46. log.error(e.getMessage(), e);
  47. }
  48. return null;
  49. }
  50. }