Преглед изворни кода

Merge branch 'develop-v3.0.0' of http://39.106.8.246:3003/FM-dev/fm-basics into develop-v3.0.0

lijie пре 3 година
родитељ
комит
0b8a4e450a

+ 15 - 1
fm-common/src/main/java/com/persagy/fm/common/constant/RegexConstants.java

@@ -1,5 +1,8 @@
 package com.persagy.fm.common.constant;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * 正则表达式常量
  *
@@ -35,7 +38,7 @@ public class RegexConstants {
     /**
      * 所有允许的特殊字符正则表达式
      */
-    private static final String ALL_CHAR_REGEX = "[!\"#\\$%&'\\(\\)\\*\\+,-\\.\\/:;<=>\\?@\\[\\\\\\]\\^\\\\`\\{\\|\\}~\\s]";
+    private static final String ALL_CHAR_REGEX = "[!\"#\\$%&'\\(\\)\\*\\+,-\\.\\/:;<=>\\?@\\[\\\\\\]\\^_`\\{\\|\\}~\\s]";
 
     private static final String EN_REGEX_EXPRESSION = LOWERCASE_REGEX + "|" + UPPERCASE_REGEX;
     private static final String EN_NUM_REGEX_EXPRESSION = EN_REGEX_EXPRESSION + "|" + NUM_REGEX;
@@ -131,4 +134,15 @@ public class RegexConstants {
      * 手机号非法提示
      */
     public static final String PHONE_REGEX_WARNING = "请输入正确手机号码";
+
+    public static void main(String[] args) {
+        String str = "zhang`._#~]";
+        String regEx = ALL_REGEX;
+        // 编译正则表达式
+        Pattern pattern = Pattern.compile(regEx);
+        Matcher matcher = pattern.matcher(str);
+        // 字符串是否与正则表达式相匹配
+        boolean rs = matcher.matches();
+        System.out.println(rs);
+    }
 }

+ 4 - 0
fm-common/src/main/java/com/persagy/fm/common/model/dto/PageDTO.java

@@ -1,5 +1,6 @@
 package com.persagy.fm.common.model.dto;
 
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import net.minidev.json.annotate.JsonIgnore;
 
@@ -15,15 +16,18 @@ import java.util.List;
  **/
 @Data
 public class PageDTO {
+    @ApiModelProperty(value = "当前页数", required = true)
     @NotNull(message = "当前页数不能为空")
     private Integer page;
 
+    @ApiModelProperty(value = "每页条数", required = true)
     @NotNull(message = "每页条数不能为空")
     private Integer size;
 
     private List<Sort> orders;
 
     @JsonIgnore
+    @ApiModelProperty(hidden = true)
     private Integer startIndex;
 
     public Integer getStartIndex() {

+ 16 - 0
fm-mybatis/src/main/java/com/persagy/fm/mybatis/annotations/FormatMybatisQueryParams.java

@@ -0,0 +1,16 @@
+package com.persagy.fm.mybatis.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * mybatis查询参数格式化注解
+ *
+ * @author lixing
+ * @version V1.0 2021/4/23 3:58 下午
+ **/
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@Inherited
+@Documented
+public @interface FormatMybatisQueryParams {
+}

+ 68 - 0
fm-mybatis/src/main/java/com/persagy/fm/mybatis/aop/FormatMybatisQueryParamsAspect.java

@@ -0,0 +1,68 @@
+package com.persagy.fm.mybatis.aop;
+
+import com.persagy.fm.mybatis.utils.MyBatisStringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * 格式化mybatis请求参数切面
+ *
+ * @author lixing
+ * @version V1.0 2021/4/23 4:00 下午
+ **/
+@Component
+@Aspect
+@Slf4j
+public class FormatMybatisQueryParamsAspect {
+    @Pointcut("@annotation(com.persagy.fm.mybatis.annotations.FormatMybatisQueryParams)")
+    private void pointCutMethod() {
+    }
+
+    @Before("pointCutMethod()")
+    public void process(JoinPoint point) throws Throwable {
+        // 获取方法的参数
+        Object[] args = point.getArgs();
+        for (Object arg : args) {
+            // 获取方法入参的属性
+            Field[] declaredFields = arg.getClass().getDeclaredFields();
+            for (Field declaredField : declaredFields) {
+                if (declaredField.getType().equals(String.class)) {
+                    Method getMethod = arg.getClass().getDeclaredMethod(
+                            "get" + MyBatisStringUtils.firstCharUpperCase(declaredField.getName()));
+                    String s = (String) getMethod.invoke(arg);
+                    s = formatUnderLine(s);
+                    Method setMethod = arg.getClass().getDeclaredMethod(
+                            "set" + MyBatisStringUtils.firstCharUpperCase(declaredField.getName()), String.class);
+                    setMethod.invoke(arg, s);
+                }
+            }
+        }
+    }
+
+    /**
+     * 格式化下划线,如果字符串中包含下划线,将下划线替换为"\_"
+     * mysql中下划线代表任意字符
+     *
+     * @param s 格式化前的字符串
+     * @return 格式化后的字符串
+     * @author lixing
+     * @version V1.0 2021/4/23 4:14 下午
+     */
+    private String formatUnderLine(String s) {
+        if (StringUtils.isBlank(s)) {
+            return s;
+        }
+        if (s.contains("_")) {
+            s = s.replaceAll("_", "\\\\_");
+        }
+        return s;
+    }
+}

+ 24 - 0
fm-mybatis/src/main/java/com/persagy/fm/mybatis/utils/MyBatisStringUtils.java

@@ -0,0 +1,24 @@
+package com.persagy.fm.mybatis.utils;
+
+/**
+ * 字符串工具类
+ *
+ * @author lixing
+ * @version V1.0 2021/4/23 4:23 下午
+ **/
+public class MyBatisStringUtils {
+    /**
+     * 首字母大写
+     *
+     * @param s 字符串
+     * @return 首字母大写后的字符串
+     * @author lixing
+     * @version V1.0 2021/4/23 4:24 下午
+     */
+    public static String firstCharUpperCase(String s) {
+        char[] cs = s.toCharArray();
+        cs[0] -= 32;
+        return String.valueOf(cs);
+
+    }
+}