标题
空值检索的解决(也是mybatis xml 的双重if)
<li>
<label>检查类型:</label>
<select name="checkType">
<option value="" th:selected="${checkType == '0'?true:false}">所有</option>
<option value="1" th:selected="${checkType == '1'?true:false}">日常检查</option>
<option value="2" th:selected="${checkType == '2'?true:false}">专项检查</option>
<option value="3" th:selected="${checkType == '3'?true:false}">双随机检查</option>
<option value="4" th:selected="${checkType == '4'?true:false}">全项检查</option>
<option value="5" th:selected="${checkType == '5'?true:false}">年检</option>
<option value="6" th:selected="${checkType == '6'?true:false}">专项整治</option>
<option value="7" th:selected="${checkType == '7'?true:false}">其他</option>
<option value='True' th:selected="${checkType == 'True'?true:false}">未标记类型</option>
</select>
</li>
xml 部分写法
<if test="checkType!=null and checkType!='' and checkType!='True'.toString() ">
and i.CHECK_TYPE = #{checkType}
</if>
<if test="checkType!=null and checkType!='' and checkType=='True'.toString() ">
and i.CHECK_TYPE is null
</if>
实体中要声明字段true;
空值查询的2种写法ex:
- and i.CHECK_TYPE is null
- and Isnull(i.CHECK_TYPE) = ‘Ture’