ERR1 : Use ‘stats.children: true‘ resp. ‘--stats-children‘ for more details

23/04/12学习回顾:
以下报错是因为ejs模板引擎,ejs语法就是<%= %>,并且在注释中也会解析


在cli中运行 npm run serve 遇见的error :
1 ERROR in child compilations (Use ‘stats.children: true’ resp. ‘–stats-children’ for more details)

  1. 在网上搜索error信息,找到以下文章
    https://blog.csdn.net/coralpapy/article/details/119383767
  2. 文章中提了一句相关error解释
    需要特别留意html模板的所在文件的绝对路径,否则会报错找不到
1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
//文件路径错误报错
  1. 于是定位error应该是由于public里面的index.html 里面
  2. 通过部分复制粘贴与源码的对比,发现在问题处在注释里面<%= %>,导致模板解析时出问题.
<head>
    <!-- 配置页签的图标,当项目实施时可能有各种路径问题,cli因此在这里把./和/转化成<%= %>,底层有一定处理-->
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <!-- 配置网页的标题<%= %> 中的内容代表来到package.json中找到name对应的名称=>webpack插件的一个功能 -->
    <title><%= htmlWebpackPlugin.options.title %></title>
</head>
  1. 之后学习中应该注意解释内容
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
这段代码看起来比较简单,但可以从以下几个方面进行优化: 1. 将 `modelMap` 改为在 `init()` 函数中初始化,而不是在每次调用 `Batch()` 函数时初始化。这样可以避免重复初始化,提高代码的性能。 2. 针对循环中的每个 `item`,可以采用批量插入(bulk insert)的方式,而不是逐个插入。这样可以减少数据库交互的次数,提高代码的性能。例如,可以将所有待插入的数据构造成一个切片,然后通过 `common.DB.CreateInBatches()` 方法进行批量插入。 3. 当出现错误时,应该立即返回错误信息,而不是继续进行循环。这样可以避免不必要的数据库交互和数据错误。 下面是一个优化后的示例代码: ``` var modelMap = map[string]interface{}{ "comb": &models.PsComb{}, "conduit": &models.PsConduit{}, "feature": &models.Feature{}, "discharger": &models.PsDischarger{}, "gate": &models.PsGate{}, "interception": &models.PsInterception{}, "lake": &models.PsLake{}, "manhole": &models.PsManhole{}, "outfall": &models.PsOutfall{}, "pipe": &models.PsPipe{}, "pumpStation": &models.PsPumpStation{}, "retention": &models.PsRetention{}, "river": &models.PsRiver{}, "wwtp": &models.PsWWTP{}, "psSystem": &models.PsSystem{}, "landUse": &models.LandUse{}, "publicity": &models.Publicity{}, } func init() { for _, model := range modelMap { common.DB.AutoMigrate(model) } } func Batch(ctx *gin.Context) { var requ Request if err := ctx.ShouldBind(&requ); err != nil { ctx.JSON(400, models.Response{ Code: 400, Msg: "参数有误", Data: err.Error(), }) return } resp := models.Response{ Code: 0, Msg: "success", } var values []interface{} for _, item := range requ.Post { if reqType, ok := modelMap[item.Type]; ok { if err := mapstructure.Decode(item.Value, reqType); err != nil { ctx.JSON(500, models.Response{ Code: 500, Msg: "创建失败", Data: err.Error(), }) return } values = append(values, reqType) } } if len(values) > 0 { res := common.DB.CreateInBatches(values, len(values)) if res.Error != nil { ctx.JSON(500, models.Response{ Code: 500, Msg: "创建失败", Data: res.Error, }) return } } ctx.JSON(200, resp) } ``` 注意,这只是一种示例代码,具体实现可能需要根据您的实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值