MyBatis动态SQL:bind

bind元素可以从OGNL表达式中创建一个变量并将其绑定到上下文:
1.mapper.xml
    <select id="selectEmployeeLikeName" resultType="org.fkit.domain.Employee">
        <bind name="pattern" value="'%' + _parameter.getName() + '%'" />
        SELECT * FROM tb_employee WHERE loginname LIKE #{pattern}
    </select>
2.mapper.java
    List<Employee> selectEmployeeLikeName(Employee employee);
3.控制器
    @GetMapping("/mysql/DynamicSQL/bind")
    public void dynamicSQLBind()
    {
        //获得SqlSession实例
        SqlSession sqlSession = FKSqlSessionFactory.getSqlSession();
        //获得Mapper接口代理对象
        EmployeeMapper em = sqlSession.getMapper(EmployeeMapper.class);
        Employee employee = new Employee();
        //设置模糊查询参数
        employee.setName("A");
        
        //获取查询结果
        List<Employee> list = em.selectEmployeeLikeName(employee);
        list.forEach(one -> System.out.println(one.getName()));
    }
4.输出