jeecgboot/JeecgBoot · error · RuntimeException
模板缺少参数:${item}
Error message
模板缺少参数:${item} What it means
DySmsHelper sends Alibaba Cloud (Dysms) SMS messages using template codes defined in DySmsEnum. Each enum entry declares required parameter keys (comma-separated). validateParam checks that every required key is present in the templateParamJson before calling the SMS API; if any key is missing it throws RuntimeException, preventing a guaranteed-to-fail API call. This is a pre-flight validation guard for SMS template parameters.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DySmsHelper.java:143
//hint 此处可能会抛出异常,注意catch
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
logger.info("短信接口返回的数据----------------");
logger.info("{Code:" + sendSmsResponse.getCode()+",Message:" + sendSmsResponse.getMessage()+",RequestId:"+ sendSmsResponse.getRequestId()+",BizId:"+sendSmsResponse.getBizId()+"}");
String ok = "OK";
if (ok.equals(sendSmsResponse.getCode())) {
result = true;
}
return result;
}
private static void validateParam(JSONObject templateParamJson,DySmsEnum dySmsEnum) {
String keys = dySmsEnum.getKeys();
String [] keyArr = keys.split(",");
for(String item :keyArr) {
if(!templateParamJson.containsKey(item)) {
throw new RuntimeException("模板缺少参数:"+item);
}
}
}
// public static void main(String[] args) throws ClientException, InterruptedException {
// JSONObject obj = new JSONObject();
// obj.put("code", "1234");
// sendSms("13800138000", obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);
// }
}
View on GitHub (pinned to 96fb33f5ec)
Solutions
- Supply every key declared in the DySmsEnum entry's getKeys() for the template you are using.
- If a template parameter is genuinely optional, split into separate enum entries or adjust getKeys.
- Log the full required-keys list alongside the error to make debugging faster.
- Add a unit test asserting sendSms is always called with all required keys.
Example fix
// before — missing required 'minutes' key
JSONObject params = new JSONObject();
params.put("code", "1234");
DySmsHelper.sendSms(phone, params, DySmsEnum.REGISTER_TEMPLATE);
// after — include all required keys
params.put("code", "1234");
params.put("minutes", "5"); Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate required SMS keys before sending
public static void validateBeforeSend(JSONObject params, DySmsEnum tpl) {
for (String key : tpl.getKeys().split(",")) {
if (!params.containsKey(key.trim()))
throw new IllegalArgumentException("Missing SMS param: " + key);
}
} Type guard
public static boolean hasAllTemplateKeys(JSONObject params, DySmsEnum tpl) {
for (String key : tpl.getKeys().split(",")) {
if (!params.containsKey(key.trim())) return false;
}
return true;
} Try / catch
try {
DySmsHelper.sendSms(phone, params, tpl);
} catch (RuntimeException e) {
if (e.getMessage().contains("模板缺少参数")) {
// fill missing keys and retry, or log
}
} Prevention
- Keep DySmsEnum key lists in sync with the Alibaba SMS template parameters.
- Build the param JSON with all keys unconditionally for a given template.
- Unit-test sendSms calls with the full required key set.
When it happens
Trigger: Calling DySmsHelper.sendSms with a JSONObject missing one of the template's declared keys — e.g. a verification-code template requiring 'code' and 'minutes' but the caller only supplies 'code'. The keys come from DySmsEnum.getKeys() for the chosen template.
Common situations: Adding a new SMS template and forgetting to supply all its parameters; changing a template's parameters in Alibaba console without updating the enum or the caller; a code path that builds the param JSON conditionally and omits a key.
Related errors
- The file name can not null
- 请注意,将要排序的列字段不存在:${column}
- 未获取到用户
- Illegal access to path outside of base directory.
- 非法业务路径,禁止访问上传目录之外的路径: ${bizPath}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/e61e729349939b91.
Report an issue: GitHub.