一个比较恶心的问题。
要查询数据。
业务要求,某json的字段的某字段的值可以是null,也可以是某个值(用户输入)
其他查询条件若干。
现在问题是,这两个条件怎么兼容在一起。
saas型项目,可有配置。
谁有什么办法么?
java,spring,后端,mybatis,mysql
where 字段名A=ifnull(用户输入的值,字段名A)
where (字段名A is null or 字段名A=用户输入的值)
这是sql语句的问题,使用left|right join ... on... 可以达到这样的效果,就是左连接或者右连接
mybatis的话,用if标签就可以实现啊
```java
select * from a
<where>
<if test="params !=null and params!='' ">
and params = #{params}
</if>
<if test="item !=null and item!='' ">
and item = #{item}
</if>
</where>
```
address为JSON字段,province 是里面的字段属性
AND (address->'$.province' = null
<if test="testColumn != null">
OR address->'$.province' = #{address}
</if>
)
我的思路是这个,不知道好不好用,你试试