null与NULL区别、where choose语句
在xml文件中,我们编写sql判断语句
<select id="select" resultType="Good">
select *
from tb_goods
/*where 1=1*/
<where>
<if test="status != NULL">
and status=#{status}
</if>
<if test="company_name != NULL and company_name !=''">
and company_name like #{company_name}
</if>
<if test="goods_name != NULL and goods_name !=''">
and goods_name like #{goods_name}
</if>
</where>
<select id="selectSingle" resultType="Good">
select *
from tb_goods
<where>
/*相当于Switch*/
<choose>
<when test="status != null">
status=#{status}
</when>
<when test=" company_name != null and company_name !=''">
company_name like #{company_name}
</when>
<when test=" goods_name != null and goods_name !=''">
goods_name like #{goods_name}
</when>
</choose>
</where>
</select>
我们可以看到查询过程中,一个使用NULL,一个使用null,如果使用NULL控制台会报错原因就在java严格区分大小写,
null是关键字,而NULL不是。
莫名其妙choose报错,导致这个区别的原因是idea存在的小bug,在使用该方法时不能在里面写注释
<where>
//这里注释不会
<choose>
//在这里面注释choose报错
</choose>
</where>