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