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查询数据,按特定顺序排序

有如下表table_city

id      city
1      beijing
2      shanghai
3      hanghzou
4      shenzhen

现在将查询出的数据按照id 3、4、1、2排序

先把id数据按照一定顺序放到一个List中

List<Integer> ids = new ArrayList<Integer>();
ids.add(3);
ids.add(4);
ids.add(1);
ids.add(2);

MyBatis mapper sql如下

<select id="findHistory" resultMap="recentlyBrowse">
    select * from
    <foreach collection="list" item="id" index="index"
        open="(" close=")" separator="union all">
        select * from table_city where id=#{id,jdbcType=DECIMAL}
    </foreach> as city
</select>

把ids作为参数传递给查询的dao方法

@Autowired
SqlSessionTemplate sql;

public List<People> findHistory(List<Integer> ids) {
    return sql.selectList(NAMESPACE + "findHistory", ids);
}

对于Mapper接口,如下:

public interface TableCityMapper {
    List<City> findHistory(@Param("list") List<Integer> ids);
}
上一篇 Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
下一篇 MyBatis根据List批量查询List结果排序问题