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 Excepti泠贾高框on { 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创建数据库和导入数据库
  • 热门搜索
    悦木之源怎么样 怎么root 怎么做饺子 急用钱又借不到怎么办 空白怎么打 开车撞死人怎么判刑 怎么烧红烧肉 荒岛求生怎么生火 怎么蒸螃蟹 湖北中医药大学怎么样