public List<BdipChatPoint> selectListByPage(String modelUrl,String username);
Mapper.xml
1 2 3 4 5 6
<selectid="selectListByPage"parameterType="java.lang.String"resultMap="pointMap"> select * from bdip_chat_point where tree_id = #{0} and user_name like #{1} </select>
main.java
1 2 3
mapper.selectListByPage("1","%tom%");
有的人在Mapper.xml可能会这样写,是取不到值的,下面是错误演示
1 2 3 4 5
<selectid="selectListByPage"parameterType="java.lang.String"resultMap="pointMap"> select * from bdip_chat_point where tree_id = #{modelUrl} and user_name like #{username} </select>
如果我们就想使用这种方法查,要怎么办呢?可以用Map封装参数,看一下使用Map传值
2.使用Map传值
Mapper.java
1 2
public List<BdipChatPoint> selectListByPage(Map map);
Mapper.xml
1 2 3 4 5 6 7
<selectid="selectListByPage"parameterType="Map"resultMap="pointMap"> select * from bdip_chat_point where tree_id = #{modelUrl} and user_name like #{username} </select>
<selectid="selectListByPage"parameterType="Map"resultMap="pointMap"> select * from bdip_chat_point where tree_id = #{modelUrl} and user_name like '%${username}%' </select>