mybatis模糊查询

时间:2019-03-19
本文章向大家介绍mybatis模糊查询,主要包括mybatis模糊查询使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<!--使用$符合动态解析  并模糊查询-->
    <select id="selectByName" parameterType="string" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from employee a
        left join department b
        on a.dept_id=b.id
        where a.name like '%${name}%'
    </select>
    <!--模糊查询:利用bind进行动态绑定:可以将OGNL表达式中的值绑定到一个变量中,方便后来引用这个变量-->
    <select id="selectByName2" parameterType="string" resultMap="BaseResultMap">
        <!--利用bind进行动态绑定:可以将OGNL表达式中的值绑定到一个变量中,方便后来引用这个变量-->
        <bind name="_name" value="'%'+name+'%'"/>
        select
        <include refid="Base_Column_List"/>
        from employee a
        left join department b
        on a.dept_id=b.id
        where a.name like #{_name}
    </select>