Mybatis Plus 中 参数传递
一、单个参数传递
List<UserVO> getUserList(String name);
UserMapper.xml
<!--查询所有用户信息-->
<select id="getUserList" resultMap="UserVOMap">
select
<include refid="col"/>
from user
where is_deleted = '0'
<if test="name != null">
and name like concat(concat('%', #{name}), '%')
</if>
</select>
二、多个参数传递
UserMapper.java
List<UserVO> getUserList( ("name") String name, ("age") Integer age, ("email") String email);
UserMapper.xml
<!--查询所有用户信息-->
<select id="getUserList" resultMap="UserVOMap">
select
<include refid="col"/>
from user
where is_deleted = '0'
<if test="name != null">
and name like concat(concat('%', #{name}), '%')
</if>
<if test="age != null">
and age = #{age}
</if>
<if test="email != null">
and email like concat(concat('%', #{email}), '%')
</if>
</select>
三、多参数传递(1)
UserMapper.java
List<UserVO> getUserList( ("userDTO") UserDTO userDTO);
UserMapper.xml
<!--查询所有用户信息-->
<select id="getUserList" resultMap="UserVOMap">
select
<include refid="col"/>
from user
where is_deleted = '0'
<if test="userDTO.name != null">
and name like concat(concat('%', #{userDTO.name}), '%')
</if>
<if test="userDTO.age != null">
and age = #{userDTO.age}
</if>
<if test="userDTO.email != null">
and email like concat(concat('%', #{userDTO.email}), '%')
</if>
</select>
四、多参数传递(2)
UserMapper.java
List<UserVO> getUserList(Map<String, Object> params);
UserMapper.xml
<!--查询所有用户信息-->
<select id="getUserList" resultMap="UserVOMap">
select
<include refid="col"/>
from user
where is_deleted = '0'
<if test="name != null">
and name like concat(concat('%', #{name}), '%')
</if>
<if test="age != null">
and age = #{age}
</if>
<if test="email != null">
and email like concat(concat('%', #{email}), '%')
</if>
</select>
版权声明:
作者:admin
链接:http://lixiaofang.top/2022/01/19/mybatis-plus-%e4%b8%ad-%e5%8f%82%e6%95%b0%e4%bc%a0%e9%80%92/
来源:码农日志
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
共有 0 条评论