mybatis-查询(resultMap 自定义结果集)-13

resultType是自动封装的,当resultType满足不了时:
1.驼峰命名法 2. resultMap

resultMap 自定义结果集 强大且重要

关闭驼峰命名法法测试

public Employee getEmpById(Integer id);
<!-- 自定义某个javaBean的封装规则
    type:自定义规则的java类型
    id:唯一方便引用
    -->
    <resultMap id="myEmp" type="com.stayreal.mybatis.Employee">
        <!-- 定义主键封装规则-->
        <id column="id" property="id"/>
        <!-- 定义普通列的封装规则,不指定的会自动封装,但推荐全部写出-->
        <result column="last_name" property="lastName"/>
        <result column="email" property="email"/>
        <result column="gender" property="gender"/>
    </resultMap>
    <!--  public Employee getEmpById(Integer id);-->
    <!-- resultMap:自定义结果集映射规则-->
    <select id="getEmpById"  resultMap="myEmp">
        select * from tbl_employee where id = #{id}
    </select>
EmployeeMapperPlus mapper = session.getMapper(EmployeeMapperPlus.class);
        Employee employee = mapper.getEmpById(1);
        System.out.println(employee.toString());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值