mybatis动态sql中的bind绑定


知识点:bind在模糊查询中的用法

    在我的博客    mybatis中使用mysql的模糊查询字符串拼接(like) 中也涉及到bind的使用

 

 

      <!-- List<Employee> getEmpsTestInnerParameter(Employee employee); -->
      <select id="getEmpsTestInnerParameter" resultType="com.hand.mybatis.bean.Employee">
          <!-- bind:可以将OGNL表达式的值绑定到一个变量中,方便后来引用这个变量的值 -->
          <bind name="bindeName" value="'%'+eName+'%'"/> eName是employee中一个属性值
          SELECT * FROM emp
          <if test="_parameter!=null">
            where ename like #{bindeName}
          </if>
      </select>

 

   测试类中:

           Employee emp=new Employee();
            emp.setEname("张");   为eName属性赋值为“张”
            List<Employee> list=mapper.getEmpsTestInnerParameter(emp);
            for (Employee employee : list) {
                System.out.println(employee);
            }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM