mybatis动态sql报错征解
在使用mybatis进行动态sql操作时,遇到报错提示"badsql",可能的原因是sql语句存在语法错误。
针对提供的sql语句:
select * from table a <where> a.project_id=#{projectid} and a.id != #{id} and a.status=3 <choose> <when test="type == idcard"> and a.id_card = #{code} </when> <when test="type == unitcode">and a.unit_code = #{code}</when> <otherwise> </otherwise> </choose> </where>
修改后,正确的sql语句应该如下:
select * from table a <where> a.project_id=#{projectId} and a.id != #{id} and a.status=3 <choose> <when test="type == 'idCard'"> and a.id_card = #{code} </when> <when test="type == 'unitCode'"> and a.unit_code = #{code} </when> <otherwise> </otherwise> </choose> </where>
修改后的部分包括:
修改后,sql语句的语法正确,可以正常执行。
以上就是MyBatis动态SQL报错“badSql”,如何修改SQL语句使其正确执行?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号