2022.08.14 学习笔记

  • Post author:
  • Post category:其他

学习笔记

mybatis 打印日志

mybatis要开启日志打印需要以下两步

  • yaml配置文件中添加:

    mybatis:
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    
  • 如果是Springboot的继承mybatis,需要配置打印日志的级别为debug

    logging.level.com.leo.mapper=debug
    

    如果配置的级别不正确,可能只会有以下输出,而不会有具体的sql语句

    Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@be56353]
    Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@be56353]
    Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@be56353]
    Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@be56353]
    

为了进一步方便查看打印日志,可以在idea中安装插件Mybatis log,可以试用30天,或者网上使用破解版。

复杂mybatis查询语句

    <select id="getIssueFilterListCount" parameterType="Map" resultType="Integer">
        SELECT COUNT(*) FROM issue
        <trim prefix="where" prefixOverrides="and">
            <if test="tagInfoList != null and tagInfoList.size > 0">
                <foreach collection="tagInfoList" separator="or" open="(" close=")" item="tagInfo">
                    <trim prefix="(" suffix=")" suffixOverrides="and">
                        repo_uuid = #{tagInfo.repoUuid} and
                        <trim prefix="(" suffix=")">
                            <trim prefix="" prefixOverrides="or">
                                <if test="tagInfo.dirList != null and tagInfo.dirList.size > 0">
                                    <foreach collection="tagInfo.dirList" separator="or" item="dir">
                                        file_name like concat(#{dir},'%')
                                    </foreach>
                                </if>
                                <if test="tagInfo.fileList != null and tagInfo.fileList.size > 0">
                                    OR file_name in
                                    <foreach collection="tagInfo.fileList" open="(" close=")" separator="," item="file">
                                        #{file}
                                    </foreach>
                                </if>
                            </trim>
                        </trim>
                    </trim>
                </foreach>
            </if>
        </trim>
    </select>

具体Sql

SELECT COUNT(*) FROM issue where ( ( repo_uuid = 'daa79834-0162-11ec-a813-bd5c25985ab0' and ( file_name like concat('src/main/java/org/example/merge/Example7','%') OR file_name in ( 'src/main/java/org/example/shangqi/longNM.java' , 'src/main/java/org/example/normal/LineFeed.java' ) ) ) or( repo_uuid = '14b560b2-565c-11ec-8879-c551b7fbdd59' and ( file_name like concat('src/main/java/redis/clients/jedis','%') or file_name like concat('src/main/java/RedisTimeout','%') ) ) );

版权声明:本文为merryghoet原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。