使用内部枚举类作为外部类的参数的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 ...
随机推荐
- vuex源码阅读分析
这几天忙啊,有绝地求生要上分,英雄联盟新赛季需要上分,就懒着什么也没写,很惭愧.这个vuex,vue-router,vue的源码我半个月前就看的差不多了,但是懒,哈哈.下面是vuex的源码分析在分析源 ...
- JavaScript 工作原理之十三-CSS 和 JS 动画底层原理及如何优化其性能
原文请查阅这里,本文采用知识共享署名 4.0 国际许可协议共享,BY Troland. 本系列持续更新中,Github 地址请查阅这里. 这是 JavaScript 工作原理的第十三章. 概述 正如你 ...
- flask之三:视图高级
视图高级 app.route和app.add_url_rule app.add_url_rule app.add_url_rule('/list/',endpoint='myweb',view_fun ...
- Nginx server name配置子域名二级域名
绑定子域名到不同目录(子站) 网站的目录结构为 /var/www/html: ├── fx └── blog└── photo html为nginx的默认网站目录. sudo vi /etc/ngin ...
- YiGo表单建立
做一个请假单表单(下图是最后的成品图) 表单的类型 实体表单 1.可存储 2.可编辑 虚拟表单 视图(不可存储数据,只有显示功能) 不可编辑 字典 报表 备注 :一张表单是实体还是虚拟取决于其数据对象 ...
- rabitmq + php
消费者 <?php //配置信息 $conn_args = array( 'host' => '127.0.0.1', 'port' => '5672', 'login' => ...
- C++ 文件操作 FILE*
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> //编程题:往文件里写入字母表的26个字母. //要求:如果字母对应编码值 是奇数则写 ...
- 一口气说出 6种,@Transactional注解的失效场景
整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 一口气说出 9种 分布式ID生成方式,面试官有点懵了 面试总被问 ...
- Natas32 Writeup(Perl 远程代码执行)
Natas32: 打开后和natas31相似的界面,并且提示,这次您需要证明可以远程代码执行,Webroot中有一个二进制文件可以执行. my $cgi = CGI->new; if ($cgi ...
- 欢乐水杯(happy glass)中流体的一种实现!图文视频讲解 ! Cocos Creator!
使用cocos creator v2.2.2 实现流体效果 ! 图文+视频讲解! 效果预览 实现原理 整体思路是参考论坛中的一个帖子 这款游戏中水的粘连效果在Construct3中利用图层很容易实现, ...