Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

MyBatis根据List批量查询List结果排序问题

MyBatis配置

public interface RouteServiceMapper {
    List<RouteService> selectRouteServiceList(@Param("routeServiceList") List<Map<String, String>> routeServiceList);
}

查询出来的RouteServiceList顺序与传入的List信息顺序不一致:

<select id="selectRouteServiceList" parameterType="java.util.List" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from route_service rs
    where
    rs.route_code in
    <foreach item="routeService" index="index" collection="routeServiceList"
             open="(" separator="," close=")">
        #{routeService.route_code}
    </foreach>
    and rs.service_code in
    <foreach item="routeService" index="index" collection="routeServiceList"
            open="(" separator="," close=")">
        #{routeService.service_code}
    </foreach>
    and rs.status = 'ENABLE'
</select>

解决方式:

<select id="selectRouteServiceList" parameterType="java.util.List" resultMap="BaseResultMap">
    select * from
    <foreach item="routeService" index="index" collection="routeServiceList"
             open="(" separator="union all" close=")">
        select <include refid="Base_Column_List"/>
        from route_service rs where
        rs.route_code=#{routeService.route_code,jdbcType=VARCHAR} and
        rs.service_code=#{routeService.service_code,jdbcType=VARCHAR} and
        rs.status = 'ENABLE'
    </foreach> as rs
</select>

SQL测试

  • 待查询数组顺序
[{"service_code":"ALIPAY_QR","route_code":"alipay"},
 {"service_code":"WECHATPAY_QR","route_code":"wechatpay"}]
  • 顺序不一致查询转义
select id, route_code, service_code, service_app_name, pay_outer, status, creation_time, modification_time 
from tp_channel_service cs 
where cs.route_code in ( 'alipay','wechatpay' ) 
  and cs.service_code in ( 'ALIPAY_QR','WECHATPAY_QR' ) 
  and cs.status = 'ENABLE'
  • 顺序一致查询转义
select id, route_code, service_code, service_app_name, pay_outer, status, creation_time, modification_time from
    (
    select id, route_code, service_code, service_app_name, pay_outer, status, creation_time, modification_time from tp_channel_service cs where
        cs.route_code='alipay' and cs.service_code='ALIPAY_QR' and cs.status = 'ENABLE'
    UNION ALL
    select id, route_code, service_code, service_app_name, pay_outer, status, creation_time, modification_time from tp_channel_service cs where
        cs.route_code='wechatpay' and cs.service_code='WECHATPAY_QR' and cs.status = 'ENABLE'
    )
as cs
上一篇 使用MyBatis查询数据,按特定顺序排序
下一篇 利用Java反射机制获取实体对象所有属性及其对应值