zoukankan      html  css  js  c++  java
  • 作业7,8

    直接上代码:

    接口:

    /**
    * 通过id查询信息
    * @param map
    * @return
    */
    Goods getGoodById(Map<String ,String > map);

    xml:

        <select id="getGoodById" resultType="com.pojo.Goods">
    
            SELECT * FROM goods where
            <choose>
                <when test="userId!=null and userId != ''">
                     goods_id = #{userId};
                </when>
                <otherwise>
    这里查询相当于switch里的default
    goods_id = 2; </otherwise> </choose> </select>

    测试类:

    test
     @Test
        public void test06(){
            SqlSession sqlSession = MyBatisUtil.createSqlSession();
    
            DemoMapper mapper = sqlSession.getMapper(DemoMapper.class);
    
           Map<String ,String > map = new HashMap<String, String>();
           map.put("userId","");
            Goods goods = mapper.getGoodById(map);
    
    
            System.out.println(goods.getGoods_code()+" "+goods.getGoods_name());
    
            MyBatisUtil.closeSqlSession(sqlSession);
        }

    结果:

    8:

    直接上代码:

    接口:

    /**
         * 分页查询
         * @param map
         * @return
         */
    List<Goods> getGoodsByLimit(Map<String ,Integer > map);
    
    

    xml:

      <select id="getGoodsByLimit" resultType="com.pojo.Goods">
    
    SELECT * FROM goods LIMIT #{parNo},#{parSize}
    
        </select>

    测试类:

  • 相关阅读:
    知多少进程?
    提高.NET应用性能
    战术设计DDD
    win7下exe文件设置为开机启动
    CQRS项目
    DDD总览
    ML.Net Model Builder
    MySQL主主复制搭建教程收集(待实践)
    MySQL主从复制搭建教程收集(待实践)
    MySQL集群方案收集
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11733382.html
Copyright © 2011-2022 走看看