Java框架MyBatis学习历程(3)——Sql传参,多表关联查询、ResultMap结果映射

本文介绍了Java框架MyBatis的学习,内容涵盖带参查询的select方法,如何进行多表关联查询,以及利用ResultMap进行结果映射,通过具体的代码实例和数据传输对象进行了详细阐述。
摘要由CSDN通过智能技术生成

1、带参查询select

在这里插入图片描述
代码实例:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="goods">
    <select id="selectAll" resultType="com.imooc.mybatis.entity.Goods">
        select  * from t_goods order by goods_id desc limit 10
    </select>
    
    <select id="selectById" parameterType="Integer" resultType="com.imooc.mybatis.entity.Goods">
        select * from t_goods where goods_id = #{value}
    </select>
    
    <select id="selectByPriceRange" parameterType="java.util.Map" resultType="com.imooc.mybatis.entity.Goods">
        select * from t_goods
        where
          current_price between #{min} and #{max}
        order by current_price
        limit 0,#{limt}
    </select>
</mapper>
    @Test
    public void testSelectById() {
   
        SqlSession session = null;
        try {
   
            session = MyBatisUtils.openSession();
            Goods goods = session.selectOne("goods.selectById", 1603);
            System.out.println(goods.getTitle());
        } catch (Exception e) {
   
            e.printStackTrace();
        } finally {
   
            MyBatisUtils.closeSession(session);
        }
    }
    @Test
    public void te
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值