MyBatis mapper文件中使用常量


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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM