zoukankan      html  css  js  c++  java
  • if

    从页面接受参数后我们会将参数打包为对象,然后将对象作为参数传给MyBatis执行查询操作,sql语句需要根据是否存在参数而动态的生成

    !-- 根据姓名或cid进行搜索-->
    <select id="searchProducts" parameterType="products" resultType="products">
        select *from products
    where 1=1
            <if test="pname != null">
                and pname like '%${pname}%'
            </if>
            <if test="cid != null">
                and cid = #{cid}
            </if>
    </select>

    @Test
    public void searchTest(){
        SqlSession session = factory.openSession();
        ProductsMapper mapper = session.getMapper(ProductsMapper.class);
        //查询条件对象
        Products condition = new Products();
        condition.setName("新疆");
        condition.setCid("s001");
        //执行查询
        List<Products> product = mapper.searchProducts(condition);
        System.out.println(product);
        session.close();
    }
     
  • 相关阅读:
    mysql各个版本下载地址
    hadoop-0.20.2完全分布式集群
    04_Spring中使用Quartz
    03_CronTrigger
    02_SimpleTrigger
    02_ActiveMQ入门
    01_JMS概述
    01_Quartz基础结构
    Java开发高性能网站需要关注的事
    06_Jedis完成MySQL的条件查询案例
  • 原文地址:https://www.cnblogs.com/huaobin/p/14162708.html
Copyright © 2011-2022 走看看