MyBatis mapper文件中使用常量
Java 开发中会经常写一些静态常量和静态方法,但是我们在写sql语句的时候会经常用到判断是否等于
//静态类
public class CommonCode {
public static String EENTERPRISE_PRODUCE = "waste_produce_enterprise"
public static String EENTERPRISE_DISPOSAL = "waste_disposal_enterp"
//内部类
public static class Enterprise {
public static String EENTERPRISE_PRODUCE = "waste_produce_enterprise";
public static String EENTERPRISE_DISPOSAL = "waste_disposal_enterprise";
}
}
我们在mapper文件中做判断
//内部类 注意**$** 符号
<if test="(type ==@com.xx.xxxx.xxxxxxxxxxxx.CommonCode$Enterprise@EENTERPRISE_DISPOSAL) ">
<if test="wasteCategory !=null and wasteCategory !=‘‘">
and wd.waste_category in(
<foreach collection="wasteCategory.split(‘,‘)" item="item" index="index" separator=",">
#{item}
</foreach>
)
</if>
</if>
//常量
<if test="(type ==@com.xx.xxxx.xxxxxxxxxxxx.CommonCode@EENTERPRISE_PRODUCE) ">
<if test="wasteCode !=null and wasteCode !=‘‘">
and wp.waste_code in(
<foreach collection="wasteCode.split(‘,‘)" item="item" index="index" separator=",">
#{item}
</foreach>
)
</if>
</if>