美文网首页
Mybatis同时传入对象参数和字符串参数

Mybatis同时传入对象参数和字符串参数

作者: 小和大大 | 来源:发表于2023-04-24 17:05 被阅读0次
1. Dao

字符串和对象参数都用@param注解.

import org.apache.ibatis.annotations.Param;

public List<User> selectAllUsers(
                        @Param("user") User user, 
                        @Param("bm") String bm);

2. mapper.xml

mapper.xml中使用的时候,使用#{对象名.属性名}取值,如#{user.id},动态SQL判断时也要用 对象名.属性名.

注意,使用了@pram注解的话在mapper.xml不加parameterType。

<select id="selectAllUsers" resultMap="UserMap">
        select *
        from user
        where bm='0000'
        <if test="user.name != null and user.name != ''">
            and name like concat(concat('%',#{user.name}),'%')
        </if>
        <if test="user.sex != null and user.sex != ''">
            and sex like concat(concat('%',#{user.sex}),'%')
        </if>
</select>


链接:https://www.jianshu.com/p/022e05f0ff7e

相关文章

网友评论

      本文标题:Mybatis同时传入对象参数和字符串参数

      本文链接:https://www.haomeiwen.com/subject/lxgujdtx.html