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创建数据库和导入数据库
  • 热门搜索
    五风十雨的意思 三火一木念什么 风流倜傥的意思 儿童钙片什么牌子好 兹证明是什么意思 改善什么填空 九朵玫瑰代表什么 tid是什么意思 挑大梁什么意思 考研英语一和英语二有什么区别