mybatis动态sql使用bind绑定

 时间:2024-10-12 20:27:26

1、bind绑定可以将ognl表达式的值绑定到一个变量中,方便后来引用这个变量的值。<bind name="_empName" value="'%' + empName +'%'"/>

mybatis动态sql使用bind绑定

3、编写单元测试代码:@Test public void test1() throws Exception { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); try { EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = new Employee(); employee.setEmpId(1); employee.setEmpName("%曹%"); List<Employee> employees = employeeMapper.getEmpsByConditionChoose(employee); System.out.println(employees); }finally { sqlSession.close(); } }

mybatis动态sql使用bind绑定

5、运行单元测试方法,查看后台打印的sql语句。

mybatis动态sql使用bind绑定

6、模糊溽朽孑臾查询我们推荐使用在代码中使用%传值。public void test1() throws Exception { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); try { EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = new Employee(); employee.setEmpId(1); employee.setEmpName("%曹%"); List<Employee> employees = employeeMapper.getEmpsByConditionChoose(employee); System.out.println(employees); }finally { sqlSession.close(); } }

mybatis动态sql使用bind绑定
  • CentOS7.4离线安装gcc
  • tomcat时区如何设置
  • 如何替换JavaScript字符串中的正斜杠
  • 接口测试工具postman之全局变量的备份与还原
  • 如何通过navicat创建数据库和导入数据库
  • 热门搜索
    例假期间可以减肥吗 日系搭配 巽寮湾旅游攻略 数学符号怎么打 手机掉到水里怎么办 普陀山简介 额头上长痘痘是怎么回事 饥荒曼德拉草怎么抓 张飞简介 魔芋减肥