select r.role_id from s_user u, s_role r,s_relate g
where r.role_id=g.role_id and userName=#{userName}
我要查询的role_id 会返回多个, 这么写对吗?
还有我的DAO层应该怎么接收, 用List<>接收。打印显示listsize=0
大神帮帮忙
两个问题
1、首先你的sql语句有问题,显然你要多表联合查询,那么应该把三张表建立连接。
2、用List<>接收是正确的,显示listsize=0,说明你的查找的几个表里没有你要查找的 userName和role_id,还有一种可能就是1中提到的sql语句错误
主要是sql写得不对,没查询出数据而已
正确的sql写法应该是
select
r.role_id
from s_role r
inner join s_user u on u.role_id = r.id
inner join s_relate g on g.role_id = r.id
where u.userName=#{userName}