作业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 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 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步