mybatis中mysql,sql能查到,但是返回结果为0的问题

匿名 (未验证) 提交于 2019-12-02 22:06:11

问题起因,多数据库支持的问题。

ORCALE下,selectFuzzyByParam方法中的sql,单独执行能找到之,方法返回值也有对应的对象。

 <select id="selectFuzzyByParam" parameterType="map" resultType="com.***.***.***.***.SysProjectDO">     <if test="queryValue != null">       <bind name="pattern1" value="'%' + queryValue + '%'" />     </if>     SELECT * FROM     (     select ID, CODE, NVL(TABLE1.TEXT,TABLE2.NAME) as NAME , STATUS, CREATOR, CREATE_TIME,     UPDATE_TIME,PROJECT_DESC AS "desc",PROJECT_TYPE AS "type" from TABLE2     LEFT JOIN TABLE1 on TABLE2.ID = TABLE1.DATA_ID     <if test="languageCode != null">       and TABLE1.LANGUAGE_CODE = #{languageCode}     </if>     )     <where>       <if test="queryValue != null">         and NAME like #{pattern1}       </if>       <if test="status != null">         and STATUS = #{status}       </if>       <if test="type != null">         and "type" = #{type}       </if>     </where>   </select>

本以为将sql中的NVL函数,换成mysql的IFNULL就可以。但是,替换后,出现很怪异的问题。单独执行sql,能查到数据。但是selectFuzzyByParam返回的集合却是空的。这种原因,应该是其中的别名设置有问题,主要是type的问题,改成如下格式后,问题解决。原因,应该是别名的处理方式不同导致的问题。oracle采用的是""的方式,而mysql采用的是``的方式。

 <select id="selectFuzzyByParam" parameterType="map" resultType="com.***.***.***.***.SysProjectDO">     <if test="queryValue != null">       <bind name="pattern1" value="'%' + queryValue + '%'" />     </if>     SELECT * FROM     (     SELECT ID as id, CODE AS code, IFNULL(TABLE1.TEXT, TABLE2.NAME) AS name,     STATUS as status, CREATOR as creator, CREATE_TIME as createTime, UPDATE_TIME as updateTime,     PROJECT_DESC AS `desc`, PROJECT_TYPE AS `type` from TABLE2     LEFT JOIN TABLE1 on TABLE2.ID = TABLE1.DATA_ID     <if test="languageCode != null">       and TABLE1.LANGUAGE_CODE = #{languageCode}     </if>     ) as tmpTable     <where>       <if test="queryValue != null">         and NAME like #{pattern1}       </if>       <if test="status != null">         and STATUS = #{status}       </if>       <if test="type != null">         and `type` = #{type}       </if>     </where>   </select>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!