站点基本信息接口完善等

This commit is contained in:
mi9688
2024-11-05 16:04:51 +08:00
parent e18e832250
commit 5c0027abeb
27 changed files with 102 additions and 870 deletions

View File

@ -1,5 +1,6 @@
package com.fastbee.common.utils.json;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONUtil;
import org.apache.commons.lang3.StringUtils;
@ -30,4 +31,16 @@ public class JsonStrUtil {
return true;
}
/**
* 验证字符串是否是json格式
*/
public static boolean isValidJson(String jsonStr) {
try {
JSONUtil.parseObj(jsonStr);
} catch (JSONException e) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,36 @@
package com.fastbee.common.utils.validate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LongitudeLatitudeValidateUtils {
/**
* 判断字符串是不是经度或者纬度
* @param str 经纬度字符串
* @return true 或 false
*/
public static boolean isLongitudeOrLatitude(String str) {
String regex = "^[-+]?\\d{1,3}(\\.\\d+)?$"; // 正则表达式,匹配经度或纬度格式
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
// 如果字符串匹配正则表达式且值的范围在经纬度范围内,则返回 true
return matcher.matches() && isValueInRange(str);
}
/**
* 判断值是否在经纬度范围内
* @param str 经纬度字符串表示的值
* @return true 如果值在范围内false 否则
*/
public static boolean isValueInRange(String str) {
try {
double value = Double.parseDouble(str);
return value >= -180 && value <= 180; // 经度范围
} catch (NumberFormatException e) {
// 字符串无法转换为数字,认为不在范围内
return false;
}
}
}