使用内部枚举类作为外部类的参数的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 == @com.hierway.vslm.domain.stream.SLineSboxesQueryParam$QueryMethod@BySpecIdList'> //<<<<<<<<<<<<<<<
AND sb.spec_id IN
<foreach collection="idList" index="index" item="item" close=")" open="(" separator=".">
#{item}
</foreach>
</when>
<when test='queryMethod == @com.hierway.vslm.domain.stream.SLineSboxesQueryParam$QueryMethod@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 >= #{startTime}
</if>
<if test="endTime != null">
AND sb.end_time <= #{endTime}
</if>
</where>
</select>
使用内部枚举类作为外部类的参数的Mybatis的参数该如何判断的更多相关文章
- Second Day: 关于Button监听事件的三种方法(匿名类、外部类、继承接口)
第一种:通过匿名类实现对Button事件的监听 首先在XML文件中拖入一个Button按钮,并设好ID,其次在主文件.java中进行控件初始化(Private声明),随后通过SetOnClickLis ...
- c++中嵌套类,外部类访问内部类的私有成员变量
在嵌套类中,内部类可以直接访问外部类的私有成员变量,但是外部类不能直接访问内部类的私有成员变量,必须把外部类声明为内部类的友元类 /********************************** ...
- C++嵌套类(内部类与外部类)
在一个类中定义的类被称为嵌套类,定义嵌套类的类被称为外部类.; //不能访问 mytest::i = 10;//不能访问 } private: class mytest { int i; int j; ...
- Java内部类与外部类的那些事
昨天去笔试的时候遇到了Java的内部类的创建方式与访问权限的问题,我不懂,没写,故今天起来特意去试验一下,就有了这篇总结性的文章. Java中的内部类又分为非静态内部类(匿名内部类也是非静态的内部类) ...
- java内部类 和外部类的区别
java 内部类和静态内部类的区别 详细连接https://www.cnblogs.com/aademeng/articles/6192954.html 下面说一说内部类(Inner Class)和 ...
- C++之内部类(内部类就是外部类的友元类,单向友元。只是内部类比友元类多了一点权限)
1. 内部类的概念 如果一个类定义在另一个类的内部,这个内部类就叫做内部类.注意此时这个内部类是一个独立的类,它不属于外部类,更不能通过外部类的对象去调用内部类.外部类对内部类没有任何优越的访问权限. ...
- 继承内部类时使用外部类对象.super()调用内部类的构造方法
问题简介 今天在看<Java编程思想>的时候,看到了一个很特殊的语法,懵逼了半天--一个派生类继承自一个内部类,想要创建这个派生类的对象,首先得创建其父类的对象,也就是这个内部类,而调 ...
- Java嵌套类,内部类和外部类
1.嵌套类,内部类 嵌套类是指被定义在一个类内部的类: JAVA的嵌套类有很多种类:1.静态成员类:2.非静态成员类:3.匿名类:4.局部类:其中,除了静态成员类之外,其他的都是内部类,因为静态成员类 ...
- java 编程基础 Class对象 反射 :获取类的构造方法,方法,成员变量,内部类,外部类,父类,实现的接口,修饰符等...
类 Class 每个类被加载之后,系统就会为该类生成一个对应的Class对象,通过该Class对象就可以访问到JVM中的这个类. 我们在Java中获取Class对象一般有三种方式: (1), 使用C ...
随机推荐
- 前端每日实战:152# 视频演示如何用纯 CSS 创作一个圆点错觉效果
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gBwzKR 可交互视频 此视频是可 ...
- JZOJ 3518. 【NOIP2013模拟11.6A组】进化序列(evolve)
3518. [NOIP2013模拟11.6A组]进化序列(evolve) (File IO): input:evolve.in output:evolve.out Time Limits: 1000 ...
- XCTF---easyjava的WriteUp
一.题目来源 题目来源:XCTF题库安卓区easyjava 题目下载链接:下载地址 二.解题过程 1.将该apk安装进夜神模拟器中,发现有一个输入框和一个按钮,随便输入信息,点 ...
- C#桌面开发的未来WebWindow
目录 WebWindow 源码 作者博客 基于Chromium的Edge 体验 体验方式一: 体验方式二: 遗留的问题 WebWindow WebWindow是跨平台的库. Web Window的当前 ...
- ffmpeg 编程常用 pcm 转 aac aac 转 pcm mp4 h264解码
ffmpeg 是现在开源的全能编解码器,基本上全格式都支持,纯 c 语言作成,相对比其它的 VLC ,GStreamer glib2 写的,开发更简单些,文档很棒,就是 examples 比较少. 常 ...
- Head First设计模式——蝇量和解释器模式
蝇量 蝇量模式:如果让某个类的一个实例能用来提供许多“虚拟实例”,就使用蝇量模式. 在一个设计房子的平台中,周围要加上一些树,树有一个坐标XY坐标位置,而且可以根据树的年龄动态将自己绘制出来.如果我们 ...
- Vue2.0 【第一季】第3节 v-for指令:解决模板循环问题
目录 Vue2.0 [第一季] 第3节 v-for指令:解决模板循环问题 第三节 v-for 指令 一.基本用法: 二.排序 三.对象循环输出 Vue2.0 [第一季] 第3节 v-for指令:解决模 ...
- Jasper报表 自动序列号
添加表达式:$V{REPORT_COUNT}.toString()
- Systematic comparison of strategies for the enrichment of lysosomes by data independent acquisition 通过DIA技术系统比较各溶酶体富集策略 (解读人:王欣然)
文献名:Systematic comparison of strategies for the enrichment of lysosomes by data independent acquisit ...
- python编写“求最大值”
# 求最大值 def large(*num): # 定义一个large函数,函数的参数为可变参数 ma = num[0] # 初始化最大值 for n in num: if ma < n: # ...