[mybatis]动态sql_bind_绑定

Posted 唐火

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[mybatis]动态sql_bind_绑定相关的知识,希望对你有一定的参考价值。

bind

<!--    public List<Employee>  getEmpsTestInnerParameter(Employee employee);-->
    <select id="getEmpsTestInnerParameter" resultType="com.atguigu.mybatis.bean.Employee">
        <!--<bind name = "_lastName" value = "'%'+lastName+'%'"/>-->
        <bind name = "_lastName" value="'%'+lastName+'%'"></bind>
        <if test = "_databaseId=='mysql'">
            select * from tb1_employee
            <if test = "_parameter!=null">
                where last_name like #_lastName
            </if>
        </if>
        <if test = "_databaseId == 'oracle'">
            select * from employees
            <if test = "_parameter!=null">
                where last_name like #_lastName
            </if>

        </if>

    </select>
    @Test
    public void test04() throws IOException 
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();

        SqlSession sqlSession = sqlSessionFactory.openSession();

        try
        
            EmployeeMapperDynamicSQL mapper = sqlSession.getMapper(EmployeeMapperDynamicSQL.class);


            Employee employee = new Employee();

            employee.setLastName("a");

            List<Employee> emps = mapper.getEmpsTestInnerParameter(employee);

            for (Employee e : emps)
            
                System.out.println(e);
            

        finally 

            sqlSession.close();

        
    

以上是关于[mybatis]动态sql_bind_绑定的主要内容,如果未能解决你的问题,请参考以下文章

JavaLearn#(27)MyBatis进阶:Mapper代理(接口绑定)多参数传递模糊查询分页自增主键回填动态SQL一级缓存二级缓存

MyBatis学习总结_11_MyBatis动态Sql语句

[刘阳Java]_MyBatis_动态SQL标签用法_第7讲

mybatis 接口绑定方案及多参数传递

Mybatis动态代理开发

MyBatis_动态SQL