后端java
public class DataScope{
public String beginTime ;
public String endTime ;
public DataScope(String beginTime,String endTime){
this.beginTime = beginTime ;
this.endTime = endTime;
}
}
Object val = map.get(s);
if(val instanceof JSONArray){
//日期between
JSONArray jval = (JSONArray)val ;
DataScope dataScope = new DataScope((String)jval.get(0),(String)jval.get(1));
List plist = new ArrayList();
plist.add(dataScope);
queryParams.put(s,plist);
}else{
queryParams.put(s, map.get(s));
}
mybatis mapping配置
<
select id="getListByPage" resultType="Map">
SELECT ${fields} FROM `${tableName}`
<choose>
<when test="params!= null and params.size>0">
WHERE
<foreach collection="params.keys" item="key" open="(" close=")" separator="and">
<choose>
<when test="params[key] instanceof java.util.List and params[key] !=null and params[key].size > 0 ">
<foreach collection="params[key]" index="index" item="item" open="(" close=")" separator="and">
${key} between #{item.beginTime} and #{item.endTime}
</foreach>
</when>
<when test="params[key].indexOf('*')>-1">
${key} LIKE REPLACE(#{params[${key}]},"*","%")
</when>
<otherwise>
${key} = #{params[${key}]}
</otherwise>
</choose>
</foreach>
<if test="superQueryMap != null and superQueryMap.size>0 ">
and
<choose>
<when test="matchType=='AND'">
<foreach collection="superQueryMap" item="value" open="(" close=")" separator="and">
<choose>
<when test="value.ruleValue=='IN'.toString()">
${value.field} ${value.ruleValue}
<foreach item="iv" collection="value.val.split(',')" open="(" separator="," close=")">
#{iv}
</foreach>
</when>
<otherwise>
${value.field} ${value.ruleValue} #{value.val}
</otherwise>
</choose>
</foreach>
</when>
<otherwise>
<foreach collection="superQueryMap" item="value" open="(" close=")" separator="or">
<choose>
<when test="value.ruleValue=='IN'.toString()">
${value.field} ${value.ruleValue}
<foreach item="iv" collection="value.val.split(',')" open="(" separator="," close=")">
#{iv}
</foreach>
</when>
<otherwise>
${value.field} ${value.ruleValue} #{value.val}
</otherwise>
</choose>
</foreach>
</otherwise>
</choose>
</if>
</when>
<otherwise>
<if test="superQueryMap != null and superQueryMap.size>0 ">
where
<choose>
<when test="matchType=='AND'">
<foreach collection="superQueryMap" item="value" open="(" close=")" separator="and">
<choose>
<when test="value.ruleValue=='IN'.toString()">
${value.field} ${value.ruleValue}
<foreach item="iv" collection="value.val.split(',')" open="(" separator="," close=")">
#{iv}
</foreach>
</when>
<otherwise>
${value.field} ${value.ruleValue} #{value.val}
</otherwise>
</choose>
</foreach>
</when>
<otherwise>
<foreach collection="superQueryMap" item="value" open="(" close=")" separator="or">
<choose>
<when test="value.ruleValue=='IN'.toString()">
${value.field} ${value.ruleValue}
<foreach item="iv" collection="value.val.split(',')" open="(" separator="," close=")">
#{iv}
</foreach>
</when>
<otherwise>
${value.field} ${value.ruleValue} #{value.val}
</otherwise>
</choose>
</foreach>
</otherwise>
</choose>
</if>
</otherwise>
</choose>
<if test="orderBy!= null">
order by ${orderBy}
</if>
</select>