作业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>

 

测试类:

 

 

 

 

本文作者:AxeBurner

本文链接:https://www.cnblogs.com/bichen-01/p/11733382.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   AxeBurner  阅读(129)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.