使用内部枚举类作为外部类的参数的Mybatis的参数该如何判断

新写了一个接口,期望根据不同的参数来给数据库中不同的字段进行传值。这里使用了内部静态枚举类的方式进行传值,在写mybatis动态sql时,如果是普通对象,一般使用,那么使用枚举类,如何判断枚举类的值呢?

Mapper接口

public class SLineSboxesQueryParam {
    private QueryMethod queryMethod;//查询方式的枚举内部类
    private List<String> idList;
    private LocalDateTime startTime;
    private LocalDateTime endTime;

 public SLineSboxesQueryParam() {
    }

//省略getter setter方法

    public void checkHasNecessaryFields() {
        if (this.queryMethod == null) {
            throw new ApiException(ResultCode.PARAMS_ERROR, "queryMethod is missing");
 } else if (CollectionUtils.isEmpty(this.idList)) {
            throw new ApiException(ResultCode.PARAMS_ERROR, "idList is missing");
 } else if (this.startTime == null) {
            throw new ApiException(ResultCode.PARAMS_ERROR, "startTime is missing");
 } else if (this.endTime == null) {
            throw new ApiException(ResultCode.PARAMS_ERROR,"endTime is missing");
 }
    }

    //定义查询方式
 public static enum QueryMethod { //此处定义了内部枚举类
        BySpecIdList, BySLineIdList, ByVplIdList;

 QueryMethod() {
        }

    }
}

mappers.xml配置

//resultMap

<resultMap id="sline_sboxes_map" type="com.hierway.vslm.domain.stream.SLineSboxesVO">
 <id column="stream_line_id" property="streamLineId"/>
 <result column="name" property="lineName"/>
 <result column="area_id" property="areaId"/>
 <result column="sl_spec_id" property="specId"/>
 <result column="sl_vpl_id" property="vplId"/>
 <result column="status" property="status"/>
 <result column="line_start_time" property="startTime"/>
 <result column="line_end_time" property="endTime"/>
 <collection property="sboxes" ofType="com.hierway.vslm.dataaccess.mybatis.dao.SBox">
 <id property="streamBoxId" column="stream_box_id"/>
 <result property="streamLineId" column="line_id"/>
 <result property="startTime" column="box_start_time"/>
 <result property="endTime" column="box_end_time"/>
 <result property="capability" column="capability"/>
 <result property="useState" column="use_state"/>
 <result property="opState" column="op_state"/>
 <result property="setId" column="set_id"/>
 <result property="reqId" column="req_id"/>
 <result property="specId" column="spec_id"/>
 <result property="preSetId" column="pre_set_id"/>
 <result property="preUseCapability" column="pre_use_capability"/>
 <result property="lastSetId" column="last_set_id"/>
 <result property="lastUseCapability" column="last_use_capability"/>
 </collection>

</resultMap>
//sql

<!-- List<SLineSboxesVO> getSLineSboxesVOByIdList(SLineSboxesQueryParam param);-->
<select id="getSLineSboxesVOByIdList" resultType="com.hierway.vslm.domain.stream.SLineSboxesQueryParam" resultMap="sline_sboxes_map">
 SELECT sl.name,sl.stream_line_id,sl.area_id,sl.spec_id as sl_spec_id,sl.vpl_id as sl_vpl_id,sl.status,sl.start_time as line_start_time,sl.end_time as line_end_time,
    sb.stream_box_id,sb.stream_line_id as line_id,sb.start_time as box_start_time,sb.end_time as box_end_time,sb.capability,sb.use_state,sb.op_state,sb.set_id,sb.req_id,sb.spec_id,
    sb.pre_set_id,sb.pre_use_capability,sb.last_set_id,sb.last_use_capability
 FROM
    stream_line as sl
    JOIN stream_box as sb ON sl.stream_line_id = sb.stream_line_id
 <where>
 <choose>
 <when test=‘queryMethod == @c[email protected]BySpecIdList‘> //<<<<<<<<<<<<<<<
 AND sb.spec_id IN
<foreach collection="idList" index="index" item="item" close=")" open="(" separator=".">
 #{item}
</foreach>
 </when>
 <when test=‘queryMethod == @c[email protected]BySLineIdList‘> //<<<<<<<<<<<<<<<
 AND sb.stream_line_id IN
 <foreach collection="idList" index="index" item="item" close=")" open="(" separator=".">
 #{item}
 </foreach>
 </when>
 <otherwise>
 AND vpl_id IN
 <foreach collection="idList" index="index" item="item" close=")" open="(" separator=".">
 #{item}
 </foreach>
 </otherwise>
 </choose>
 <if test="startTime != null">
 AND sb.start_time &gt;= #{startTime}
        </if>
 <if test="endTime != null">
 AND sb.end_time &lt;= #{endTime}
        </if>
 </where>

</select>

原文地址:https://www.cnblogs.com/yiweiblog/p/12652529.html

时间: 2024-08-01 06:42:28

使用内部枚举类作为外部类的参数的Mybatis的参数该如何判断的相关文章

解决内存泄漏更加清楚的认识到Java匿名类与外部类的关系

1.事件起因 在做项目的时候,通过Android Studio的Memory Monitor窗口观察程序内存使用情况,发现当程序退出的时候,有一部分应该释放掉的内存没有释放掉,知道程序中应该有内存泄漏了.为了发现程序中的内存泄漏,我切换了IDE工具到Eclipse,里面安装了内存泄漏的分析工具MAT,具体怎么用MAT分析内存泄漏可以自己Google,我把我自己找到内存泄漏的地方贴出来 从上图中可以看到,有24M左右的内存被mView(其实它真正是一个Fragment)这个变量持有,导致Java垃

四种监听器(自身类,外部类,内部类,匿名类)

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ThisClassEvent extends JFrame implements ActionListener{ public ThisClassEvent(){ setLayout(new FlowLayout()); JButton btn=new JButton("ok"); add(btn); btn.addActionL

C++嵌套类(内部类与外部类)

在一个类中定义的类被称为嵌套类,定义嵌套类的类被称为外部类.对类进行嵌套通常是为了帮助实现另一个类,并避免名称冲突. 对类嵌套往往为了帮助实现另一个类,并避免名称冲突.如下: class queue { private: struct Node{ Item item;struct Node *next }; ... }; 由于struct在默认情况下其成员为公有的,   所以Node实际上是一个嵌套类. 作用域 嵌套类的声明位置决定了嵌套类的作用域,即它决定了程序的那部分可以创建嵌套类的对象.

Java内部类与外部类的那些事

昨天去笔试的时候遇到了Java的内部类的创建方式与访问权限的问题,我不懂,没写,故今天起来特意去试验一下,就有了这篇总结性的文章. Java中的内部类又分为非静态内部类(匿名内部类也是非静态的内部类)和静态内部类,两者与外部类的关系是不一样的,创建的方式也不一样. 1 非静态内部类 Java的非静态内部类在构造的时候,会将外部类的引用传递进来,并且作为内部类的一个属性,因此,内部类会隐式地持有其外部类的引用.也就是非静态内部类在构造的时候需要有一个外部类的实例传递进来进行构造,不能像普通的Jav

内部类和外部类之间的相互调用

内部类: ①静态内部类中可以有非静态的方法 ②当内部类中有静态方法或者静态成员变量时,一定是静态内部类 一般内部类在外部类的成员变量位置,像这样: 1 public class Outer { 2 class Inner{ 3 4 } 5 } 1.外部类访问内部类: 内部类被static修饰:可以直接new Inner in = new Inner(); 内部类没有被static修饰:得先new出来外部类的实例,再new内部类的 Inner in = new Outer().new Inner(

内部类和 外部类相互访问

内部类: ①静态内部类中可以有非静态的方法 ②当内部类中有静态方法或者静态成员变量时,一定是静态内部类 1.外部类访问内部类: 内部类被static修饰:可以直接new Inner in = new Inner(); 内部类没有被static修饰:得先new出来外部类的实例,再new内部类的 Inner in = new Outer().new Inner(); 2.内部类访问外部类:(外部类.this.变量) 3.外部类和内部类中的方法相互访问: ①外部类的静态方法test和非静态内部类的非静

内部类练习题(外部类访问内部类成员、内部类访问外部类成员、顶级类访问内部类成员)

package com.Summer_0429.cn; /** * @author Summer * 内部类实例: * 定义一只猫类,猫有: * 1.重量 * 2.猫的身体: * 1)颜色 * 2)显示猫的身体的信息(): * 3.显示猫的整体信息(): * 要求:创建一只小猫,显示它的整体信息. * */ class Cat{ private double weight; public Cat(double weight){ this.weight = weight; } //内部类:成员内部

Java嵌套类,内部类和外部类

1.嵌套类,内部类 嵌套类是指被定义在一个类内部的类: JAVA的嵌套类有很多种类:1.静态成员类:2.非静态成员类:3.匿名类:4.局部类:其中,除了静态成员类之外,其他的都是内部类,因为静态成员类更像是一个独立的类: 但是静态成员类,是外部类内部的一个成员,静态成员类的访问和其他的静态成员一样:1.通过外部类类名调用:2.如果静态成员类定义为私有,那么只能在外部类内部使用        JAVA 内部类可以很好的实现隐藏,并且内部类拥有外围类的所有元素的访问权限,可是实现多重继承,并且可以避

python中的嵌套类(内部类调用外部类中的方法函数)

在为书中版本是3.X的,但2.X不太支持直接调用. 所以,在PYTHON2.X中,要在内部类中调用外部类的方法,就必须得实例化外部类,然后,传入实例进行调用. 花了我两个小时啊,资料没找到,自己一个一个想法调试,真的失败了三四十次,PRINT了N多~~~:) class DiagramFactory: @classmethod def make_diagram(Class, width, height): return Class.Diagram(width, height) @classmet