通用的 核心模块

在 ruoyi-common 模块下,创建通用的核心子模块 ruoyi-common-core ,其 pom.xml 内容:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <parent>
  6. <groupId>com.ruoyi</groupId>
  7. <artifactId>ruoyi-common</artifactId>
  8. <version>1.0.0</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11. <artifactId>ruoyi-common-core</artifactId>
  12. </project>

版本号声明

在 ruoyi 父工程中,声明版本号

  1. <dependency>
  2. <groupId>com.ruoyi</groupId>
  3. <artifactId>ruoyi-common-core</artifactId>
  4. <version>${ruoyi.version}</version>
  5. </dependency>

通用的返回结果集

  1. package com.ruoyi.common.core.domain;
  2. import com.ruoyi.common.core.constant.Constants;
  3. import java.io.Serializable;
  4. /**
  5. * 响应信息主体
  6. *
  7. * @author ruoyi
  8. */
  9. public class R<T> implements Serializable {
  10. private static final long serialVersionUID = 1L;
  11. /**
  12. * 成功
  13. */
  14. public static final int SUCCESS = Constants.SUCCESS;
  15. /**
  16. * 失败
  17. */
  18. public static final int FAIL = Constants.FAIL;
  19. private int code;
  20. private String msg;
  21. private T data;
  22. public static <T> R<T> ok() {
  23. return restResult(null, SUCCESS, null);
  24. }
  25. public static <T> R<T> ok(T data) {
  26. return restResult(data, SUCCESS, null);
  27. }
  28. public static <T> R<T> ok(T data, String msg) {
  29. return restResult(data, SUCCESS, msg);
  30. }
  31. public static <T> R<T> fail() {
  32. return restResult(null, FAIL, null);
  33. }
  34. public static <T> R<T> fail(String msg) {
  35. return restResult(null, FAIL, msg);
  36. }
  37. public static <T> R<T> fail(T data) {
  38. return restResult(data, FAIL, null);
  39. }
  40. public static <T> R<T> fail(T data, String msg) {
  41. return restResult(data, FAIL, msg);
  42. }
  43. public static <T> R<T> fail(int code, String msg) {
  44. return restResult(null, code, msg);
  45. }
  46. private static <T> R<T> restResult(T data, int code, String msg) {
  47. R<T> apiResult = new R<>();
  48. apiResult.setCode(code);
  49. apiResult.setData(data);
  50. apiResult.setMsg(msg);
  51. return apiResult;
  52. }
  53. public int getCode() {
  54. return code;
  55. }
  56. public void setCode(int code) {
  57. this.code = code;
  58. }
  59. public String getMsg() {
  60. return msg;
  61. }
  62. public void setMsg(String msg) {
  63. this.msg = msg;
  64. }
  65. public T getData() {
  66. return data;
  67. }
  68. public void setData(T data) {
  69. this.data = data;
  70. }
  71. }

通用常量类

  1. package com.ruoyi.common.core.constant;
  2. /**
  3. * 通用常量信息
  4. *
  5. * @author ruoyi
  6. */
  7. public class Constants {
  8. /**
  9. * UTF-8 字符集
  10. */
  11. public static final String UTF8 = "UTF-8";
  12. /**
  13. * GBK 字符集
  14. */
  15. public static final String GBK = "GBK";
  16. /**
  17. * http请求
  18. */
  19. public static final String HTTP = "http://";
  20. /**
  21. * https请求
  22. */
  23. public static final String HTTPS = "https://";
  24. /**
  25. * 成功标记
  26. */
  27. public static final Integer SUCCESS = 200;
  28. /**
  29. * 失败标记
  30. */
  31. public static final Integer FAIL = 500;
  32. /**
  33. * 登录成功
  34. */
  35. public static final String LOGIN_SUCCESS = "Success";
  36. /**
  37. * 注销
  38. */
  39. public static final String LOGOUT = "Logout";
  40. /**
  41. * 注册
  42. */
  43. public static final String REGISTER = "Register";
  44. /**
  45. * 登录失败
  46. */
  47. public static final String LOGIN_FAIL = "Error";
  48. /**
  49. * 当前记录起始索引
  50. */
  51. public static final String PAGE_NUM = "pageNum";
  52. /**
  53. * 每页显示记录数
  54. */
  55. public static final String PAGE_SIZE = "pageSize";
  56. /**
  57. * 排序列
  58. */
  59. public static final String ORDER_BY_COLUMN = "orderByColumn";
  60. /**
  61. * 排序的方向 "desc" 或者 "asc".
  62. */
  63. public static final String IS_ASC = "isAsc";
  64. /**
  65. * 验证码 redis key
  66. */
  67. public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
  68. /**
  69. * 验证码有效期(分钟)
  70. */
  71. public static final long CAPTCHA_EXPIRATION = 2;
  72. /**
  73. * 令牌有效期(分钟)
  74. */
  75. public final static long TOKEN_EXPIRE = 720;
  76. /**
  77. * 参数管理 cache key
  78. */
  79. public static final String SYS_CONFIG_KEY = "sys_config:";
  80. /**
  81. * 字典管理 cache key
  82. */
  83. public static final String SYS_DICT_KEY = "sys_dict:";
  84. /**
  85. * 资源映射路径 前缀
  86. */
  87. public static final String RESOURCE_PREFIX = "/profile";
  88. }

使用

别的模块如果要使用的话,只需要引入该模块

  1. <dependency>
  2. <groupId>com.ruoyi</groupId>
  3. <artifactId>ruoyi-common-core</artifactId>
  4. </dependency>