使用内部枚举类作为外部类的参数的Mybatis的参数该如何判断
2024-08-31 08:33:35
新写了一个接口,期望根据不同的参数来给数据库中不同的字段进行传值。这里使用了内部静态枚举类的方式进行传值,在写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>
最新文章
- POJ2513-Colored Sticks
- android入门:第一天
- JS实现回到顶部效果
- RMS问题整理
- Log4Net 手册
- 解决Apache CXF 不支持传递java.sql.Timestamp和java.util.HashMap类型问题
- lightning mdb 源代码分析(2)
- mac下的ssh自动登陆
- CI 在nginx中出现404错误的解决方式
- jq 图片上传
- 用C语言写一个“事件”的模拟程序
- LCA(ST倍增)
- [物理学与PDEs]第5章第2节 变形的描述, 应变张量 2.2 Cauchy - Green 应变张量
- 从文件中读取数组数据————Java
- javaScrpit 开端
- 【转】BAT批处理中的字符串处理详解(字符串截取)
- 关于Unity中NGUI的3D角色血条的实现
- [No0000116]SQLServer启用sa账户
- linux下卸载mysql(rpm)
- 正则表达式 &; re
热门文章
- http请求缓存头详解
- Java多态实现的机制
- 关于使用fastjson出现的问题:com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 1, fastjson-version 1.2.44
- python 深浅拷贝 元组 字典 集合操作
- C语言程序设计(九) 指针
- C++ 回调函数,拷贝文件
- can do / will do / should do 情态动词
- Dubbo之服务暴露
- Java多线程并发04——合理使用线程池
- 是的,GitHub APP 终于上线了