TestMain.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package org.jeecg;
  2. import org.springframework.http.HttpHeaders;
  3. import org.springframework.http.MediaType;
  4. import java.time.Period;
  5. import java.util.regex.Pattern;
  6. /**
  7. * @Description: TODO
  8. * @author: scott
  9. * @date: 2022年05月10日 14:02
  10. */
  11. public class TestMain {
  12. public static void main(String[] args) {
  13. // // 请求地址
  14. // String url = "https://api.boot.jeecg.com/sys/user/list";
  15. // // 请求 Header (用于传递Token)
  16. // HttpHeaders headers = getHeaders();
  17. // // 请求方式是 GET 代表获取数据
  18. // HttpMethod method = HttpMethod.GET;
  19. //
  20. // System.out.println("请求地址:" + url);
  21. // System.out.println("请求方式:" + method);
  22. //
  23. // // 利用 RestUtil 请求该url
  24. // ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
  25. // if (result != null && result.getBody() != null) {
  26. // System.out.println("返回结果:" + result.getBody().toJSONString());
  27. // } else {
  28. // System.out.println("查询失败");
  29. // }
  30. // AfterIncidentDetailLog incidentDetailLog = new AfterIncidentDetailLog();
  31. // System.out.println(JSONObject.toJSONString(incidentDetailLog));
  32. // Pattern p=Pattern.compile("^ABC");
  33. // p.pattern();//返回 \
  34. System.out.println(Pattern.matches("^ABC.", "ABCA"));
  35. String ageString = "3年2月4日";
  36. ageString = ageString.replace("年","Y");
  37. ageString = ageString.replace("月","M");
  38. ageString = ageString.replace("周","W");
  39. ageString = ageString.replace("日","D");
  40. // 将年龄字符串解析为Period对象
  41. Period agePeriod = Period.parse("P" + ageString);
  42. // 获取年龄的总天数
  43. int ageInDays = agePeriod.getYears() * 365 + agePeriod.getMonths() * 30 + agePeriod.getDays();
  44. System.out.println("年龄为 " + ageString + " 的人的天数为 " + ageInDays + " 天");
  45. }
  46. private static HttpHeaders getHeaders() {
  47. String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
  48. System.out.println("请求Token:" + token);
  49. HttpHeaders headers = new HttpHeaders();
  50. String mediaType = MediaType.APPLICATION_JSON_VALUE;
  51. headers.setContentType(MediaType.parseMediaType(mediaType));
  52. headers.set("Accept", mediaType);
  53. headers.set("X-Access-Token", token);
  54. return headers;
  55. }
  56. }