Mybatis联合查询记录,左连接参数操作

公司业务需求要做个列表的排序

而实际排序的字段不再本库中,需要跨库去拿到字段,因为是微服务体系架构,不可能Left join跨库的表,所以决定调用一次跨服务的API拿到排序相关的对象,里面包含需要排序的列

一块拿到sql中进行排序(因为order by比较方便。。。。)

然后开始出现了bug,我把跨服务拿到的对象存成List集合,需要在sql中左连接才能使用里面的字段,但是直接这样写就会出现bug:

ScheduleDictionary

left join

(select O.Id AS OrgId,O.`Code`,O.`Name` from #{param.orgModels} O)

AS Org on ScheduleDictionary.OrganizationId=Org.OrgId

bug的日志打印大约是这样:

You have  an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near'_binary'??\0sr\0java.util.ArrayListx??↔??a?♥\0I\0sizexp\0\0\0w\0\0\0t\0
google了一下,只有一个问题是跟这个相关的,所以决定记录一下把,
问了下领导,这样直接left join一个list集合是不行的,需要拆开:

拆开的办法是使用union join 例如:select 1 as id,tt as name union join select 2 as id ,dd as name .....最后拼成一张表,
而我传过去的是个List肯定要用foreach循环

就这样就可以把它当作一张表去与主表连接了,

同样也可以拿到 主键或者code去下面进行排序操作了,

 









posted @ 2019-04-02 13:29  挖苦  阅读(3037)  评论(0编辑  收藏  举报