zoukankan      html  css  js  c++  java
  • SpringBoot——Mybatis踩坑日记

    20.12.17——动态SQL报错

    问题描述:手动写了一段SQL如下,控制台报错,找不到原因

       <select id="mybatisQueryBrandByPage" resultType="Brand">
            SELECT id,name,image,letter FROM tb_brand
            <where>
                <if test="key!=null and key!=''">
                    name like concat("%",#{key},"%") or letter =#{key}
                </if>
                <if test="sortBy!=null and sortBy!=''">
                   ORDER BY ${sortBy}
                </if>
                <choose>
                   <when test="desc==true"> DESC</when>
                   <otherwise> ASC</otherwise>
                </choose>
            </where>
           
        </select>              

    问题原因:

    key为空时会生成如下SQL,SELECT id,name,image,letter FROM tb_brand WHERE OREDER BY.......

    解决方法:

    配置yml文件,开启mybatis日志,查看mybatis生成的SQL和执行的细节,找到问题原因,配置如下:

    mybatis:
      type-aliases-package: com.leyou.*.pojo
      mapper-locations: classpath*:mapper/*Mapper.xml
      configuration:
        map-underscore-to-camel-case: true
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl   //开启日志
  • 相关阅读:
    网络面试题2
    网络
    Linux os
    操作系统面试题2
    操作系统面试题
    Linux
    算法-字符全排列
    第k大数问题
    地址
    ListView里面嵌套CheckBox
  • 原文地址:https://www.cnblogs.com/sheng-se/p/14151997.html
Copyright © 2011-2022 走看看