新写了一个接口,期望根据不同的参数来给数据库中不同的字段进行传值。这里使用了内部静态枚举类的方式进行传值,在写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 &gt;= #{startTime}
</if>
<if test="endTime != null">
AND sb.end_time &lt;= #{endTime}
</if>
</where> </select>

最新文章

  1. POJ2513-Colored Sticks
  2. android入门:第一天
  3. JS实现回到顶部效果
  4. RMS问题整理
  5. Log4Net 手册
  6. 解决Apache CXF 不支持传递java.sql.Timestamp和java.util.HashMap类型问题
  7. lightning mdb 源代码分析(2)
  8. mac下的ssh自动登陆
  9. CI 在nginx中出现404错误的解决方式
  10. jq 图片上传
  11. 用C语言写一个“事件”的模拟程序
  12. LCA(ST倍增)
  13. [物理学与PDEs]第5章第2节 变形的描述, 应变张量 2.2 Cauchy - Green 应变张量
  14. 从文件中读取数组数据————Java
  15. javaScrpit 开端
  16. 【转】BAT批处理中的字符串处理详解(字符串截取)
  17. 关于Unity中NGUI的3D角色血条的实现
  18. [No0000116]SQLServer启用sa账户
  19. linux下卸载mysql(rpm)
  20. 正则表达式 &amp; re

热门文章

  1. http请求缓存头详解
  2. Java多态实现的机制
  3. 关于使用fastjson出现的问题:com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 1, fastjson-version 1.2.44
  4. python 深浅拷贝 元组 字典 集合操作
  5. C语言程序设计(九) 指针
  6. C++ 回调函数,拷贝文件
  7. can do / will do / should do 情态动词
  8. Dubbo之服务暴露
  9. Java多线程并发04——合理使用线程池
  10. 是的,GitHub APP 终于上线了