public List getAllModelNode(String pid,String mids){
Map map = new HashMap();
map.put("mids", mids);
map.put("pid", pid); List list = null;
List nodeList = new ArrayList();
try {
list = sqlMapClient.queryForList("selectAllModelNode",map);
System.out.println(list.size());
for(int i=0;i<list.size();i++){
T_Model tm = (T_Model)list.get(i);
List childList = getAllModelNode(tm.getMODEL_ID(),mids);
tm.setList(childList);
nodeList.add(tm);
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(nodeList.size());
return nodeList;
}
xml配置
<select id="selectAllModelNode" parameterClass="java.util.Map" resultClass="Model">
select * from T_Model
where model_id in (#mids#)
and f_model_id = #pid#
and useable_flag = 1
order by display_order asc </select>
测试方法调用
List list = new ModelDaoImpl4Ibatis().getAllModelNode("0","1,2,3,5,6,7,8,9")
求解:mids作为以","分隔的字符串参数传递进去,是不是ibatis不支持?还是?如何解决?
7 个解决方案
#1
友情帮顶!
#2
多参数,要么用Map,要么用Bean
#3
如果相传字符串sql的话:(#mids#)改为($mids$)
如果想传集合或者数组的话:
#mids#为集合或者数组
如果想传集合或者数组的话:
<select id="selectAllModelNode" parameterClass="java.util.Map" resultClass="Model">
select * from T_Model
where model_id in (
<iterate conjunction="," property="mids">
#mids#
</iterate>
)
and f_model_id = #pid#
and useable_flag = 1
order by display_order asc </select>
#mids#为集合或者数组
#4
报什么错误啊 List list = new ModelDaoImpl4Ibatis().getAllModelNode("0","1,2,3,5,6,7,8,9")
你用正常的参数试试 啊能通过
你用正常的参数试试 啊能通过
#5
<!-- 分页查询表所有属性 -->
<select id="selectPageAll" parameterType="Ele" resultType="Users">
select t1.* from (select rownum as recnum, t2.* from(select * from
employee
<where>
<if test="usName!=null">
And name=#{usName}
</if>
<if test="usAge!=null">
And age=#{usAge}
</if>
<if test="usEmail!=null">
And email=#{usEmail}
</if>
</where>
order by id) t2 )t1 where t1.recnum>=#{pageStart} and
t1.recnum<=#{pageEnd}
</select>
我的xml
用bean
不知道你那个正确不?
#6
3楼正解
#7
楼主想一想,肯定不可以啊
SQL语句最后会变为:
select * from T_Model
where model_id in ('1,2,3,4,5,6')
and f_model_id = 0
and useable_flag = 1
order by display_order asc
这种当然差不多结果。
3楼的楼主可以尝试下。
SQL语句最后会变为:
select * from T_Model
where model_id in ('1,2,3,4,5,6')
and f_model_id = 0
and useable_flag = 1
order by display_order asc
这种当然差不多结果。
3楼的楼主可以尝试下。
#1
友情帮顶!
#2
多参数,要么用Map,要么用Bean
#3
如果相传字符串sql的话:(#mids#)改为($mids$)
如果想传集合或者数组的话:
#mids#为集合或者数组
如果想传集合或者数组的话:
<select id="selectAllModelNode" parameterClass="java.util.Map" resultClass="Model">
select * from T_Model
where model_id in (
<iterate conjunction="," property="mids">
#mids#
</iterate>
)
and f_model_id = #pid#
and useable_flag = 1
order by display_order asc </select>
#mids#为集合或者数组
#4
报什么错误啊 List list = new ModelDaoImpl4Ibatis().getAllModelNode("0","1,2,3,5,6,7,8,9")
你用正常的参数试试 啊能通过
你用正常的参数试试 啊能通过
#5
<!-- 分页查询表所有属性 -->
<select id="selectPageAll" parameterType="Ele" resultType="Users">
select t1.* from (select rownum as recnum, t2.* from(select * from
employee
<where>
<if test="usName!=null">
And name=#{usName}
</if>
<if test="usAge!=null">
And age=#{usAge}
</if>
<if test="usEmail!=null">
And email=#{usEmail}
</if>
</where>
order by id) t2 )t1 where t1.recnum>=#{pageStart} and
t1.recnum<=#{pageEnd}
</select>
我的xml
用bean
不知道你那个正确不?
#6
3楼正解
#7
楼主想一想,肯定不可以啊
SQL语句最后会变为:
select * from T_Model
where model_id in ('1,2,3,4,5,6')
and f_model_id = 0
and useable_flag = 1
order by display_order asc
这种当然差不多结果。
3楼的楼主可以尝试下。
SQL语句最后会变为:
select * from T_Model
where model_id in ('1,2,3,4,5,6')
and f_model_id = 0
and useable_flag = 1
order by display_order asc
这种当然差不多结果。
3楼的楼主可以尝试下。