SmartCommonUtils.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package net.lab1024.smartadmin.util;
  2. import org.apache.commons.lang3.StringUtils;
  3. import java.net.URISyntaxException;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. public class SmartCommonUtils {
  8. public static String getWebRootPath(String filePath) {
  9. try {
  10. String path = SmartCommonUtils.class.getClassLoader().getResource("").toURI().getPath();
  11. path = path.replace("/WEB-INF/classes/", "");
  12. path = path.replace("/target/classes/", "");
  13. path = path.replace("file:/", "");
  14. if (StringUtils.isEmpty(filePath)) {
  15. return path;
  16. } else {
  17. return path + "/" + filePath;
  18. }
  19. } catch (URISyntaxException e) {
  20. throw new RuntimeException(e);
  21. }
  22. }
  23. public static boolean isEmpty(Object o) {
  24. if (o == null) {
  25. return true;
  26. } else {
  27. if (o instanceof String) {
  28. if (o.toString().trim().equals("")) {
  29. return true;
  30. }
  31. } else if (o instanceof List) {
  32. if (((List)o).size() == 0) {
  33. return true;
  34. }
  35. } else if (o instanceof Map) {
  36. if (((Map)o).size() == 0) {
  37. return true;
  38. }
  39. } else if (o instanceof Set) {
  40. if (((Set)o).size() == 0) {
  41. return true;
  42. }
  43. } else if (o instanceof Object[]) {
  44. if (((Object[])((Object[])o)).length == 0) {
  45. return true;
  46. }
  47. } else if (o instanceof int[]) {
  48. if (((int[])((int[])o)).length == 0) {
  49. return true;
  50. }
  51. } else if (o instanceof long[] && ((long[])((long[])o)).length == 0) {
  52. return true;
  53. }
  54. return false;
  55. }
  56. }
  57. }