zoukankan      html  css  js  c++  java
  • mybatis 模糊查询

    mybatis 执行模糊查询有两种方式:

      第一种:

        模糊查询定义在sql语句上,一般不建议

         TbStudent tbStudent = tbStudentMapper.getStuByName("zhangsan");
            System.out.printf(tbStudent.toString());

      

     <select id="getStuByName" parameterType="String" resultMap="myStu">
            select * from tb_student where u_name like #{%name%}
        </select>

      第二种:

        模糊查询的条件定义在java代码里,建议使用该方法

           String uName="%zhang%";
            //System.out.printf(student.getuName());
            TbStudent tbStudent = tbStudentMapper.getStuByName(uName);
            System.out.printf(tbStudent.toString());
      <select id="getStuByName" parameterType="String" resultMap="myStu">
            select * from tb_student where u_name like #{name}
        </select>

    DEBUG [main] - ==>  Preparing: select * from tb_student where u_name like ?
    DEBUG [main] - ==> Parameters: %zhang%(String)
    DEBUG [main] - <==      Total: 1
    TbStudent{uId=1, uName='zhangsan', sex='男', tId=101, tbTeacher=null}
  • 相关阅读:
    2018.7.12训练赛 -K
    winter 2018 02 01 关于模运算的一道题
    debug(实验)
    problem-1003(恢复一下)
    hd acm1466
    hd acm2045
    hd acm 1297
    hd acm1005
    hd acm1425
    概率趣题:三个犯人
  • 原文地址:https://www.cnblogs.com/liudingwei/p/12758680.html
Copyright © 2011-2022 走看看