jeecgboot/JeecgBoot · error · JeecgBootException
消息模板不存在,模板编码:${templateCode}
Error message
消息模板不存在,模板编码:${templateCode} What it means
In SysBaseApiImpl.sendTemplateAnnouncement, the message template is looked up from sys_sms_template by templateCode. If the query returns null or an empty list, there is no template to render, so a JeecgBootException is thrown before any title/content substitution. Sending is therefore impossible until a template exists.
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java:514
// 同步发送第三方APP消息
wechatEnterpriseService.sendMessage(message, true);
dingtalkService.sendMessage(message, true);
} catch (Exception e) {
log.error("同步发送第三方APP消息失败!", e);
}
}
@Override
public void sendTemplateAnnouncement(TemplateMessageDTO message) {
String templateCode = message.getTemplateCode();
String title = message.getTitle();
Map<String,String> tmplateParam = message.getTemplateParam();
String fromUser = message.getFromUser();
String toUser = message.getToUser();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if(sysSmsTemplates==null||sysSmsTemplates.size()==0){
throw new JeecgBootException("消息模板不存在,模板编码:"+templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
//模板标题
title = title==null?sysSmsTemplate.getTemplateName():title;
//模板内容
String content = sysSmsTemplate.getTemplateContent();
if(tmplateParam!=null) {
for (Map.Entry<String, String> entry : tmplateParam.entrySet()) {
String str = "${" + entry.getKey() + "}";
if(oConvertUtils.isNotEmpty(title)){
title = title.replace(str, entry.getValue());
}
content = content.replace(str, entry.getValue());
}
}
String mobileOpenUrl = null;
if(tmplateParam!=null && oConvertUtils.isNotEmpty(tmplateParam.get(CommonConstant.MSG_HREF_URL))){
mobileOpenUrl = tmplateParam.get(CommonConstant.MSG_HREF_URL);View on GitHub (pinned to 96fb33f5ec)
Solutions
- Verify the code exists: SELECT * FROM sys_sms_template WHERE template_code = ?.
- Create the missing template via the message-template management UI.
- Check for trailing spaces and case sensitivity in the supplied templateCode.
Example fix
// before
sysBaseApi.sendTemplateAnnouncement(msg); // templateCode 'welcome' missing
// after: guard the call against a missing template
List<SysMessageTemplate> t = sysMessageTemplateService.selectByCode(msg.getTemplateCode());
if (t == null || t.isEmpty()) {
log.warn("模板缺失: {}", msg.getTemplateCode());
return; // or fall back to a plain-text announcement
}
sysBaseApi.sendTemplateAnnouncement(msg); Defensive patterns
Strategy: validation
Validate before calling
// Verify the template exists before sending.
List<SysMessageTemplate> rows = sysMessageTemplateService.selectByCode(templateCode);
if (rows == null || rows.isEmpty()) {
log.warn("消息模板缺失: {}", templateCode);
return; // or fall back to plain text
} Type guard
public boolean templateExists(String code) {
List<SysMessageTemplate> r = sysMessageTemplateService.selectByCode(code);
return r != null && !r.isEmpty();
} Try / catch
try {
sysBaseApi.sendTemplateAnnouncement(msg);
} catch (JeecgBootException e) {
if (e.getMessage() != null && e.getMessage().startsWith("消息模板不存在")) {
return Result.error("消息模板未配置: " + msg.getTemplateCode());
}
throw e;
} Prevention
- Seed required templates via a Flyway/migration script so every environment has them.
- Centralize template codes as constants shared between sender and config.
- Audit for deleted templates that are still referenced by code.
When it happens
Trigger: Calling sysBaseApi.sendTemplateAnnouncement(...) with a templateCode for which no sys_sms_template row exists — deleted, never created, typo, or a code from a different environment.
Common situations: Template created in dev but missing in prod; case/whitespace mismatch in the code; template was deleted but code references remain; code copied from documentation that doesn't exist in this deployment.
Related errors
- 发送消息失败,消息内容为空!
- DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!
- 解析SQL模板异常
- 下载word模版失败: {message}
- 生成word文档失败: {message}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/4d390d68ea03cd7a.
Report an issue: GitHub.