分类 技术相关 下的文章

批量插入 Mybatis批量insert

void batchInsert(@Param("list") List<Bean> list);

<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true">
  insert into aaa( info_id, `name`, event, event_time )
  VALUES
  <foreach collection="list"  separator="," item="item">
    (#{item.infoId},
    #{item.name},
    #{item.event},
    #{item.eventTime}
  </foreach>
</insert>

核心使用的是:foreach values。

核心点:

使用activated事件,被keep-alive 缓存的组件激活时调用
》在路由进入之前标记来源

beforeRouteEnter(to, from, next) {
  if (from.name == 'aaaa') { // 这个name是下一级页面的路由name
    to.meta.isBack = true; // 设置为true说明你是返回到这个页面
  }
  next();
},

activated() { 
  console.log('被keep-alive 缓存的组件激活时调用')
  if (this.$route.meta.isBack) { 
    console.log("页面回退执行刷新")
    this.reInit(); //执行重新请求方法
  }
  this.$route.meta.isBack = false
},

使用场景:

待审核列表,打开审核后,再次回到列表中,列表页面应该重新请求数据。

按多字段排序::

Comparator<VO> bya = Comparator.comparing(VO::getAppId).reversed();//按照a升序
Comparator<VO> byb = Comparator.comparing(VO::getNum).reversed();//按照b降序
Collections.sort(resultlist,bya.thenComparing(byb));

按单字段降序排序

Collections.sort(resultlist,(a, b)->b.getNum().compareTo(a.getNum()));

核心代码如下

      List picList = new ArrayList();
        try{
            String basepath= ServletContextFactory.getServletContext().getRealPath("/");
            String path="userfiles/pics";
            File toSaveFile=new File(basepath+path);
            Collection<File> listFiles = FileUtils.listFiles(toSaveFile,"jpg".split(","),false);
            if(listFiles!=null && listFiles.size()>0){
                for (File file : listFiles){
                 picList.add(file.getName());
                }
            }
            
        }catch (Exception e){
            logger.error("得到文件夹下的所有指定格式文件列表异常",e);
        }

代码解析

1.String basepath= ServletContextFactory.getServletContext().getRealPath("/");
获取项目根路径地址。

2.Collection<File> listFiles = FileUtils.listFiles(toSaveFile,"jpg".split(","),false);
列出指定目录jpg格式的所有文件。false,代表不扫描子目录

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。