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创建数据库和导入数据库
  • 热门搜索
    简历特长爱好怎么写 dw是什么牌子 卡介苗化脓后如何处理 幼儿腹泻怎么办 boy是什么牌子 管培生是什么意思 如何煮粽子 生态鱼缸怎么换水 8月是什么星座 移动路由器怎么用