flipped-aurora/gin-vue-admin · error
模板不能为空!
Error message
模板不能为空!
What it means
autoCodePackage.Create() validates the incoming SysAutoCodePackageCreate in a switch. The first case returns '模板不能为空!' when info.Template is the empty string — a package must declare which code-generation template it uses.
Source
Thrown at server/service/system/auto_code_package.go:33
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/flipped-aurora/gin-vue-admin/server/utils/ast"
"github.com/flipped-aurora/gin-vue-admin/server/utils/autocode"
"github.com/pkg/errors"
"gorm.io/gorm"
)
var AutoCodePackage = new(autoCodePackage)
type autoCodePackage struct{}
// Create 创建包信息
// @author: [piexlmax](https://github.com/piexlmax)
// @author: [SliverHorn](https://github.com/SliverHorn)
func (s *autoCodePackage) Create(ctx context.Context, info *request.SysAutoCodePackageCreate) error {
switch {
case info.Template == "":
return errors.New("模板不能为空!")
case info.Template == "page":
return errors.New("page为表单生成器!")
case info.PackageName == "":
return errors.New("PackageName不能为空!")
case token.IsKeyword(info.PackageName):
return errors.Errorf("%s为go的关键字!", info.PackageName)
case info.Template == "package":
if info.PackageName == "system" || info.PackageName == "example" {
return errors.New("不能使用已保留的package name")
}
default:
break
}
if !errors.Is(global.GVA_DB.Where("package_name = ? and template = ?", info.PackageName, info.Template).First(&model.SysAutoCodePackage{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同PackageName")
}
create := info.Create()
return global.GVA_DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {View on GitHub (pinned to 3136500ef3)
Solutions
- Set the template field in the request body (e.g. "package" for a package template).
- Add required-field validation in the frontend form before submitting.
- Check the JSON field name matches the request struct's binding tag so Template actually deserializes.
- Retry the create call once template is selected.
Example fix
// before
await api.createPackage({ packageName: 'order' }) // template omitted
// after
await api.createPackage({ template: 'package', packageName: 'order' }) Defensive patterns
Strategy: validation
Validate before calling
// pre-submit validation on the client
if (!form.template) {
ElMessage.warning('请选择模板')
return
}
await api.createPackage(form) Try / catch
try {
await svc.Create(ctx, info)
} catch (err) {
if (err.Error() == "模板不能为空!") {
// return 400 with guidance to pick a template
} else {
return err
}
} Prevention
- Mark template as a required field in the create form
- Block submit until a template is selected
- Match the JSON key names to the request struct binding tags
- Add API-level schema validation for required fields
When it happens
Trigger: Calling the auto-code package create API with a body where the template field is empty: omitted in JSON, sent as "", or bound from a form that never set the template.
Common situations: Frontend save button enabled before the user picks a template; API consumers constructing the payload manually and skipping the field; older clients using a renamed field name so Template binds empty.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/080b3e621ec45a22.
Report an issue: GitHub.