mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
fix:参数管理保存json类型出错bug
This commit is contained in:
parent
e76a8d547b
commit
777265c730
2 changed files with 7 additions and 1 deletions
|
|
@ -39,7 +39,7 @@ public class SysParamsDTO implements Serializable {
|
||||||
|
|
||||||
@Schema(description = "值类型")
|
@Schema(description = "值类型")
|
||||||
@NotBlank(message = "{sysparams.valuetype.require}", groups = DefaultGroup.class)
|
@NotBlank(message = "{sysparams.valuetype.require}", groups = DefaultGroup.class)
|
||||||
@Pattern(regexp = "^(string|number|boolean|array)$", message = "{sysparams.valuetype.pattern}", groups = DefaultGroup.class)
|
@Pattern(regexp = "^(string|number|boolean|array|json)$", message = "{sysparams.valuetype.pattern}", groups = DefaultGroup.class)
|
||||||
private String valueType;
|
private String valueType;
|
||||||
|
|
||||||
@Schema(description = "备注")
|
@Schema(description = "备注")
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,12 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
||||||
break;
|
break;
|
||||||
case "json":
|
case "json":
|
||||||
try {
|
try {
|
||||||
|
// 首先检查是否以 { 开头,以 } 结尾
|
||||||
|
String trimmedValue = paramValue.trim();
|
||||||
|
if (!trimmedValue.startsWith("{") || !trimmedValue.endsWith("}")) {
|
||||||
|
throw new RenException(ErrorCode.PARAM_JSON_INVALID);
|
||||||
|
}
|
||||||
|
// 然后尝试解析JSON
|
||||||
JsonUtils.parseObject(paramValue, Object.class);
|
JsonUtils.parseObject(paramValue, Object.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RenException(ErrorCode.PARAM_JSON_INVALID);
|
throw new RenException(ErrorCode.PARAM_JSON_INVALID);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue