postgresql 在mybatis中不等于怎么写?

sunny8675 2017-06-12 10:37:28
原句
select * from bib where 1=1 and p.type != '2630593'

mybatis中

<select id="query" parameterType="java.util.HashMap" resultMap="resultMap">
select * from bib b where 1=1
<trim suffixOverrides=",">
<if test="type != null">
and b.type != #{type}
</if>
</trim>
order by b.date desc
</select>

判断中的不等于写法始终执行的是等于
...全文
3165 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengzyf 2018-09-17
  • 打赏
  • 举报
回复
这样写试试,pgsql 中不等于之后,还要加上 or 字段 is null 条件
<select id="query" parameterType="java.util.HashMap" resultMap="resultMap">
select * from bib b where 1=1
<trim suffixOverrides=",">
<if test="type != null">
and b.type != #{type}
or b.type is null
</if>
</trim>
order by b.date desc
</select>

951

社区成员

发帖
与我相关
我的任务
社区描述
PostgreSQL相关内容讨论
sql数据库数据库架构 技术论坛(原bbs)
社区管理员
  • PostgreSQL社区
  • yang_z_1
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧